Untitled
unknown
plain_text
a year ago
3.1 kB
2
Indexable
Never
int main() { int choice; char dir_name[256]; char file_name[256]; char content[256]; while (1) { printf("\n----- Menu -----\n"); printf("1: Create a directory\n"); printf("2: Create and write to a file\n"); printf("3: Get working directory\n"); printf("4: Save /var/log/apt/history.log to a file\n"); printf("5: Save /proc/meminfo memory to file\n"); printf("6: Create a sub-directory and move a file to sub-directory\n"); printf("7: Change directory\n"); printf("8: List directory contents recursively\n"); printf("9: Remove a file\n"); printf("10: Remove a directory\n"); printf("Enter your choice (0 to exit): "); scanf("%d", &choice); switch (choice) { case 0: exit(0); case 1: printf("Enter the directory name you want to create: "); scanf("%s", dir_name); mode_t mode; printf("Enter the mode of the created directory (e.g., 755): "); scanf("%o", &mode); create_directory(dir_name, mode); break; case 2: printf("Enter the file name you want to create: "); scanf("%s", file_name); create_write_file(file_name, "Operating System is Fun!!"); break; case 3: get_working_dir(); break; case 4: read_historylog_to_file("/tmp/history.log"); break; case 5: read_proc_meminfo_to_file("/tmp/meminfo.txt"); break; case 6: printf("Enter the sub-directory name you want to create: "); scanf("%s", dir_name); printf("Enter the mode of the created sub-directory (e.g., 755): "); scanf("%o", &mode); printf("Enter the name of the file you want to move: "); scanf("%s", file_name); create_subdirectory_and_move_file(dir_name, mode, file_name); break; case 7: printf("Enter the directory name you want to change to: "); scanf("%s", dir_name); change_directory(dir_name); break; case 8: printf("Enter the starting directory for listing: "); scanf("%s", dir_name); directory_listing(dir_name); break; case 9: printf("Enter the file name you want to remove: "); scanf("%s", file_name); remove_file(file_name); break; case 10: printf("Enter the directory name you want to remove: "); scanf("%s", dir_name); remove_directory(dir_name); break; default: printf("Invalid choice. Please try again.\n"); } } return 0; }