Added README files for exercises
This commit is contained in:
96
exercises/mycp/README.md
Normal file
96
exercises/mycp/README.md
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
# 📄 mycp – A Simple File Copy Utility in C
|
||||||
|
|
||||||
|
`mycp` is a basic implementation of the Unix `cp` command written in C.
|
||||||
|
It copies the contents of one file into another, handling errors and signals safely.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
mycp/
|
||||||
|
├── mycp.c # Main program source
|
||||||
|
├── Makefile # Build and test automation
|
||||||
|
└── test/
|
||||||
|
└── run_tests.sh # Automated test and Valgrind report
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚙️ Build Instructions
|
||||||
|
|
||||||
|
To compile the program:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
To clean up build files:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make clean
|
||||||
|
```
|
||||||
|
|
||||||
|
To remove test artifacts as well:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make distclean
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧪 Running Tests
|
||||||
|
|
||||||
|
The test script:
|
||||||
|
|
||||||
|
- Creates temporary test files
|
||||||
|
- Runs `mycp` and compares results with `cmp`
|
||||||
|
- Uses **Valgrind** to check for memory issues
|
||||||
|
|
||||||
|
Run the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make test
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./mycp SOURCE DEST
|
||||||
|
```
|
||||||
|
|
||||||
|
- `SOURCE`: Path to the file to copy from.
|
||||||
|
- `DEST`: Path to the file to copy to.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./mycp input.txt output.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧠 Learning Objectives
|
||||||
|
|
||||||
|
- Open/read/write/close file descriptors
|
||||||
|
- Use of `open(2)`, `read(2)`, `write(2)`, and `close(2)`
|
||||||
|
- Error handling (`perror`, `errno`)
|
||||||
|
- Use of `Makefile` and basic testing with shell scripts
|
||||||
|
- Optional: use of `lseek` for advanced length computation
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Requirements
|
||||||
|
|
||||||
|
- GCC (C11)
|
||||||
|
- POSIX-compliant system (Linux, macOS)
|
||||||
|
- [Valgrind](https://valgrind.org/) for memory leak analysis (optional, used in tests)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📄 License
|
||||||
|
|
||||||
|
Educational use only. No license required.
|
||||||
|
|
||||||
107
exercises/tree/README.md
Normal file
107
exercises/tree/README.md
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
# 🗂️ tree – Directory Tree Viewer in C
|
||||||
|
|
||||||
|
A simplified implementation of the Unix `tree` command in C.
|
||||||
|
This utility recursively traverses a directory and prints its structure in a tree-like format.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
tree/
|
||||||
|
├── main.c # Entry point
|
||||||
|
├── tree.c # Directory traversal logic
|
||||||
|
├── tree.h # Function declarations
|
||||||
|
├── Makefile # Build & test automation
|
||||||
|
└── test/
|
||||||
|
└── run_tests.sh # Automated tests + Valgrind
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚙️ Build Instructions
|
||||||
|
|
||||||
|
To compile the program:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
To clean up build files:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make clean
|
||||||
|
```
|
||||||
|
|
||||||
|
To remove test artifacts as well:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make distclean
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧪 Running Tests
|
||||||
|
|
||||||
|
The test script:
|
||||||
|
|
||||||
|
- Creates a temporary directory structure
|
||||||
|
- Runs the program and compares its output to the expected result
|
||||||
|
- Performs memory leak analysis with **Valgrind**
|
||||||
|
|
||||||
|
To run all tests:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make test
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./tree [DIRECTORY]
|
||||||
|
```
|
||||||
|
|
||||||
|
If no directory is specified, the current directory (`.`) is used.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./tree testdir
|
||||||
|
```
|
||||||
|
|
||||||
|
Sample output:
|
||||||
|
|
||||||
|
```
|
||||||
|
|-- file1.txt
|
||||||
|
|-- sub1
|
||||||
|
|-- file2.txt
|
||||||
|
|-- sub2
|
||||||
|
|-- file3.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧠 Learning Objectives
|
||||||
|
|
||||||
|
- Use of `opendir`, `readdir`, and `closedir` to iterate directories
|
||||||
|
- Handling file paths and recursion
|
||||||
|
- Working with `stat` to detect subdirectories
|
||||||
|
- Implementing simple CLI programs in C
|
||||||
|
- Using `Makefile` and Valgrind for tooling and quality
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Requirements
|
||||||
|
|
||||||
|
- GCC (C11)
|
||||||
|
- POSIX-compliant system (Linux, macOS)
|
||||||
|
- [Valgrind](https://valgrind.org/) for memory checking (optional, used in tests)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📄 License
|
||||||
|
|
||||||
|
Educational use only. No license required.
|
||||||
|
|
||||||
Reference in New Issue
Block a user