C Program Basic logging of user input/output

How to write a C Program Basic logging of user input/output ?


Solution:

#include <stdio.h>

void main(void){
char fname[20];
char lname[20];

printf("Please Enter Your First Name: ");
scanf("%s", &fname);//This way will not include things after space

printf("Please Enter Your Last Name: ");
scanf("%s", &lname);//This way will not include things after space

FILE *f;
f = fopen("name.log","a");
fprintf(f,"%s %s \n",fname, lname);
fclose(f);

printf("Hello %s,\nYour name as been saved.\n", fname);

printf("=============================\n");
printf("Name Log Data\n");
printf("=============================\n");

char t;
f = fopen("name.log","r");
while((t = fgetc(f)) != EOF )
printf("%c", t);

fclose(f);

printf("-------------------------------\n");
printf("Please Press Enter to Continue.");
getchar();
getchar();
}

C Program Quadratic equation


Learn More :