ACP4_7

//BCA Support //www.bcasupport.xyz #include <stdio.h> void main() { FILE *fp; struct{ char fname[20],lname[20],city[20]; int contact; }temp,data[5]={ {"Ramesh","Patel","Mumbai",0}, {"Laila","Gupta","Delhi",4321}, {"Suresh","Patel","Mumbai",7996}, {"Krishna","Singh","Delhi",1134}, {"Tony","Stark","Malibu",3321} }; char city[20]; int a; clrscr(); fp=fopen("data.dat","w+"); for(a=0;a<5;a++) fwrite(&data[a],sizeof(data[a]),1,fp); rewind(fp); printf("\nEnter city name : "); gets(city); printf("\nName\t\tCity\t\tContact\n"); for(a=0;a<5;a++) { fread(&temp,sizeof(temp),1,fp); if(stricmp(temp.city,city)==0) { printf("\n%s %s",data[a].fname,data[a].lname); printf("\t%s\t\t%d",data[a].city,data[a].contact); } } fcloseall(); getch(); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.