Advertisement
metalx1000

Basic logging of user input/output

Nov 26th, 2012
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void main(void){
  4.     char fname[20];
  5.     char lname[20];
  6.  
  7.     printf("Please Enter Your First Name: ");
  8.     scanf("%s", &fname);//This way will not include things after space
  9.  
  10.     printf("Please Enter Your Last Name: ");
  11.     scanf("%s", &lname);//This way will not include things after space
  12.  
  13.     FILE *f;
  14.     f = fopen("name.log","a");
  15.     fprintf(f,"%s %s \n",fname, lname);
  16.     fclose(f);
  17.    
  18.     printf("Hello %s,\nYour name as been saved.\n", fname);
  19.  
  20.     printf("=============================\n");
  21.     printf("Name Log Data\n");
  22.     printf("=============================\n");
  23.  
  24.     char t;
  25.     f = fopen("name.log","r");
  26.     while((t = fgetc(f)) != EOF )  
  27.         printf("%c", t);
  28.  
  29.     fclose(f);
  30.  
  31.     printf("-------------------------------\n");
  32.     printf("Please Press Enter to Continue.");
  33.     getchar();
  34.     getchar();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement