#include #include char name[30],location[30]; int i; void menu(); void menu1(); void dataip(),srchname(),srchlocn(); void main() { void menu(),dataip(); int choice; FILE *file; do{ menu(); printf("Enter ur Choice:\n"); scanf("%d",&choice); switch(choice) { case 1:dataip(); file=fopen("dbase.txt","a"); if(ferror(file)) { printf("\nCannot Open File\n"); exit(); } fprintf(file,"Software Name : %s\n",name); for(i=0;i<30;i++) fprintf(file,"Software Location : %c\n\n",&location[i]); fclose(file); break; case 2:menu1(); printf("Enter ur Choice\n"); scanf("%d",&choice); if(choice==1) srchname(); else if(choice==2) srchlocn(); else printf("\n\nINVALID OPTION\n\n"); break; default:printf("\n\nINVALID OPTION\n\n"); } printf("\n\nContinue? (1/0):\n"); scanf("%d",&choice); }while(choice!=0); } void menu() { printf("1.Enter location info about a software into DataBase\n"); printf("2.Search for location of a software from DataBase on CDs\n\n"); } void menu1() { printf("\n1.Search By Software name\n"); printf("2.Search By Location\n\n"); } void dataip() { printf("\nEnter Name of the software\n"); /* for(i=0;i<30;i++)*/ scanf("%s",name); printf("\nEnter the location info of the above software\n"); /* for(i=0;i<30;i++)*/ scanf("%s",location); } void srchname() { FILE *p; char temp[30]; printf("\n\nEnter the name of software\n:"); /* for(i=0;i<30;i++)*/ scanf("%s",name); p=fopen("dbase.txt","r"); if(ferror(p)) { printf("\nCannot Open File\n"); exit(); } while(!feof(p)) { for(i=0;i<30;i++) fscanf(p,"%c",&temp[i]); if(strcmp(name,temp)) { for(i=0;i<30;i++) fscanf(p,"%c",&location[i]); printf("Name: %s\tLocation: %s",temp,location); } } fclose(p); } void srchlocn() { FILE *p; char temp[30]; printf("\n\nEnter the Location/CD-name\n:"); for(i=0;i<30;i++) scanf("%c",&location[i]); p=fopen("dbase.txt","r"); if(ferror(p)) { printf("\nCannot Open File\n"); exit(); } while(!feof(p)) { for(i=0;i<30;i++) fscanf(p,"%c",&temp[i]); if(strcmp(location,temp)==1) { for(i=0;i<30;i++) fscanf(p,"%c",&name[i]); printf("Name: %s\tLocation: %s",name,temp); } } fclose(p); }