I'm writing a library system and need to search for a book entered in the system to renew it. But my search refuses to work

Code

 void search(){ // function to locate a record
   int barc;
  char search_aulname[28],search_aufname[28],search_stufname[28],search_stulname[28],searchbk_title[500];
  char aulastname[28],aufirstname[28],stufirstname[28],stulastname[28],bktitle[500],date[120],genre[28];
  FILE*fp;
   system("cls");
   printf("*****************************************\n");
   printf("ENTER AUTHOR LAST NAME OF ITEM:\n");
   fgets(search_aulname,28,stdin);
    printf("ENTER AUTHOR FIRST NAME OF ITEM:\n");
   fgets(search_aufname,28,stdin);
    printf("ENTER STUDENT LAST NAME:\n");
    fgets(search_stulname,28,stdin);
    printf("ENTER STUDENT FIRST NAME OF ITEM:\n");
    fgets(search_stufname,28,stdin);
    printf("ENTER BOOK TITLE:\n");
   fgets(searchbk_title,28,stdin);
   fp=fopen("G:\\DALBBS\\ACTIVE BOOK LOANS","rb");
    while (!feof(fp)){
          fscanf(fp,"%d\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n",&barc,&aulastname,&aufirstname,&stulastname,&stufirstname,&bktitle,&genre,&date);
          if ((strcmpi(search_aulname,aulastname)==0)&&(strcmpi(search_aufname,aufirstname)==0)&&(strcmpi(search_stulname,stulastname)==0)&&(strcmpi(searchbk_title,bktitle)==0)){
                                 printf("Book has been found");
                                 getchar();
                                 }
          else{
               printf("Not working!");
               getchar();
                                 }
}
}

i need this solution now or i'm gonna fail. this is my last post here so please no warning about code tags, i'm trying but i need help urgently!!!!!!!!!!!!!!!!!!!

Edited 4 Years Ago by mike_2000_17: Fixed formatting

When you are fscanf()'ing a char array, you need to just have the name of the array - that IS a const pointer to the base of the array.

You need to remove the '&' in front of the char arrays that you will be scanning:

while (!feof(fp)){

fscanf(fp,"%d\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n",&barc,&aulastname,&aufirstname,&stulastname,&stufirstname,&bktitle,&genre,&date);

if ((strcmpi(search_aulname,aulastname)==0)&&(strcmpi(search_aufname,aufirstname)==0)&&(strcmpi(search_stulname,stulastname)==0)&&(strcmpi(searchbk_title,bktitle)==0)){

Use the '&' for numbers of all kinds, and for char's, but not for strings. Goes for fscanf(), scanf(), sscanf(), etc.

Edited 6 Years Ago by Adak: n/a

This article has been dead for over six months. Start a new discussion instead.