Question: I want another code, but the same result for this code.. #include #include #include int main(void) { char choice; while(1){ printf(Enter the mode (E: for
I want another code, but the same result for this code..
#include
int main(void) { char choice; while(1){ printf("Enter the mode (E: for data entrance, S: to search for a person data, T: terminate) "); scanf("%c",&choice); getchar(); if(choice == 'E'){ FILE* fptr = fopen("database.txt","w"); for(int i=1;;i++) { char name[100]; char address[1000]; char account_number[1000]; int balance;
printf("person %d name: ",i);
char ch = getchar(); if(ch == ' '){ break; } int j=0; while(ch != ' '){ name[j]=ch; ch = getchar(); j++; } printf("person %d address: ",i); scanf("%s",address);
printf("person %d account number: ",i); scanf("%s",account_number);
printf("person %d balance: ",i); scanf("%d",&balance); getchar();
fprintf(fptr, "%s %s %s %d ", name, address, account_number, balance); } fclose(fptr); } else if(choice == 'S'){ printf("Enter the mode of the person: "); char name[100]; scanf("%s",name); getchar(); FILE* fptr = fopen("database.txt","r"); while(1){ char curr_name[100]; char address[1000]; char account_number[1000]; int balance;
if(fscanf(fptr,"%s %s %s %d ",curr_name,address,account_number,&balance) == EOF){ printf("Not found "); break; }
if(strcmp(curr_name,name)==0){ printf("Name: %s ",curr_name); printf("Address: %s ",address); printf("Account number: %s ",account_number); printf("Balance: %d ",balance); break; } } fclose(fptr); } else if(choice == 'T'){ break; } else{ printf("%c Wrong Input ",choice); } }
printf("Thanks for you time ..... "); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
