I'am writing a program in C language and my code is working perfectly i just need to add a search to it ...
My code lets users add companies, and then display them on screen...
i would like to add a search that allows user to type company name and then displayall its info on the screen !!
THANK YOU IN ADVANCE
#include <stdio.h>
struct Company
{
char name[30];
int id;
int rev;
int debt;
};
int main(){
struct Company a[3],b[3];
FILE *fptr;
int i;
fptr=fopen("file.txt","wb");
for(i=0;i<3;++i)
{
fflush(stdin);
printf("Enter Company name: ");
gets(a.name);
printf("Enter id: ");
scanf("%d",&a.id);
printf("Enter revenue: ");
scanf("%d",&a.rev);
printf("Enter debt: ");
scanf("%d",&a.debt);
}
fwrite(a,sizeof(a),1,fptr);
fclose(fptr);
fptr=fopen("file.txt","rb");
fread(b,sizeof(b),1,fptr);
for(i=0;i<3;++i)
{
printf("Name: %s\nid: %d\nrevenue: %d\ndebt: %d",b.name,b.id,b.rev,b.debt);
}
fclose(fptr);
}