I am working with a code which stores the information of customers in a file called customer_details.txt
then asks the user to enter a name and then searches for the name in customer_details.txt, if the name is found, the entire details of the user is displayed on the output screen.
here is what I have done:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
char name[20],dob[12],add[50];
int acc_no,i=0,random=95867;
double mob_no;
fp=fopen("customer_details.txt","a+");
if(fp==NULL)
{
cout<<"Error opening file customer_details.txt !!";
exit(1);
}
cout<<"\n\nEnter name:";
cin>>name;
cout<<"\n\nEnter Date of Birth:(Date Month and Year separated by `-' ex: 25-01-1994)\n:";
gets(dob);
cout<<"\nEnter mobile number:";
cin>>mob_no;
cout<<"Enter address:\n";
gets(add);
acc_no=random+1;
fprintf(fp,"\n\n\tUser ID: %d",i+1);
i++;
fprintf(fp,"\n\t Account number: %d",acc_no);
fprintf(fp,"\n\t Name: %s",name);
fprintf(fp,"\n\t Date of Birth: %s",dob);
fprintf(fp,"\n\t Mobile no.: %lf",mob_no);
fprintf(fp,"\n\t Address: %s ",add);
fclose(fp);
getch();
}
where I need help is how to search for that particular name in the file.
thanx in advance..