This C program demonstrates fundamental file operations including creating, reading, writing, and appending data to files.
- Create Files: Create new empty files
- Write Files: Write content to files (overwrites existing content)
- Read Files: Read and display file contents
- Append Files: Add content to the end of existing files
task 1/
├── file handling.c # Main source code
├── file handling.exe # Compiled executable
└── README.md # This documentation
gcc "file handling.c" -o "file handling.exe"Run the executable and follow the menu-driven interface:
- Create a new file: Creates an empty file with the specified name
- Write to a file: Writes content to a file (overwrites existing content)
- Read from a file: Displays the current contents of a file
- Append to a file: Adds content to the end of an existing file
- Exit: Terminates the program
- Choose option 1 to create a new file (e.g., "test.txt")
- Choose option 2 to write initial content to the file
- Choose option 3 to read and verify the content
- Choose option 4 to append additional content
- Choose option 3 again to see the updated content
- Choose option 5 to exit
- Language: C
- Libraries: stdio.h, stdlib.h, string.h
- Buffer Size: 1000 characters for content input
- File Modes:
- "w" for write/create operations
- "r" for read operations
- "a" for append operations
The program includes error checking for:
- File creation failures
- File opening errors for read/write/append operations
- Invalid menu selections
- Files are created in the same directory as the executable
- Maximum content length per operation is 999 characters
- The program uses
fgets()for safe string input handling