I need to log what I type while the program is running.
this is saved in a text file.
Then next time I run the program I have the choice of restoring what is stored in the log file.
This a simple version of my code.
Code:#include <stdio.h> #include <string.h> void Log(); void Save(); void Del(); void Dir(); typedef struct { char n; struct files *next; }files; struct root { files files[50]; int count; }root; static int h; int main() { int choice; root.count = 0; h = root.count; Log(); do { printf("\nPlease select an option (1-4):\n"); printf("1) Save\n"); printf("2) Del\n"); printf("3) Dir\n"); printf("4) Quit\n"); scanf("%d",&choice); switch (choice) { case 1: if (h <50) Save(); else printf("Directory Full\n"); break; case 2: Del(); break; case 3: if (h == 0) printf("No Files Found\n"); else Dir(); break; case 4: break; default: printf("Invalid choice\n"); break; } } while(choice != 4); fclose(outfile); return 0; } void Log() { char filename[25]; printf("Enter Log filename -> "); scanf("%s", filename); outfile = fopen(filename, "a"); } void Save() { printf("\nEnter a char: "); scanf("%s",&root.files[h].n); h++; root.count = h; } void Del() { int i; char c; char hex = 0xE5; printf("\nEnter a char to del: "); scanf("%s",&c); for(i=0; i < h; i++) { if (root.files[i].n == c) { root.files[i].n = hex; } } } void Dir() { int i; char hex = 0xE5; for(i=0; i < h; i++) { if (root.files[i].n != hex){ printf("%c\n",root.files[i].n); } } }