Class Activity - USP - 1
Class Activity - USP - 1
Class Activity - USP - 1
This example illustrates how to use UNIX file-related APIs for basic file
operations.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
void list_files() {
DIR *dir = opendir(".");
struct dirent *entry;
if (dir == NULL) {
perror("Error opening directory");
return;
}
return 0;
}
return 0;
}
How to Compile and Run
1. Save the code to a file, e.g., text_editor.c.
2. Open a terminal and navigate to the directory containing the file.
3. Compile the code:
gcc -o text_editor text_editor.c
4. Run the program:
To create a file:
./text_editor create myfile.txt
To append text to the file:
./text_editor append myfile.txt "Hello, world!"
To read the contents of the file:
./text_editor read myfile.txt
To delete the file:
./text_editor delete myfile.txt