0
I want to make a function that searches my library.txt and returns a prinf output on whether the book exists within the file
void search(FILE *fptr){ FILE *fptr2; fptr = fopen("library.txt","r"); if (fptr == NULL){ printf("Error! opening file"); } fptr2 = fopen("output.txt","a+"); if (fptr2 == NULL){ printf("Error! opening file"); } char s[80]; int i; struct book b; struct library l; printf("Enter title of book.\n"); scanf("%s",&s); fscanf(fptr,"%s %d",&b.title,&l.num_books); if(fgets(s[80],l.num_books,*b.title)==1){ printf("the book %s is currently available.\n",s); } if(fgets(s[80],l.num_books,b.title)!=1){ printf("the book %s is currently not available.\n",s); } fclose(fptr); fclose(fptr2); }
2 Réponses
+ 1
You should use some regex library, that would be much better for searching.
0
Stfu