I want to make a function that searches my library.txt and returns a prinf output on whether the book exists within the file | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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); }

16th Dec 2018, 8:25 AM
Keith Owino
Keith Owino - avatar
2 Respostas
+ 1
You should use some regex library, that would be much better for searching.
19th Dec 2018, 5:30 PM
šŸ‡µšŸ‡° Danish Khan šŸ‡µšŸ‡°
šŸ‡µšŸ‡° Danish Khan šŸ‡µšŸ‡° - avatar
0
Stfu
27th Dec 2018, 11:50 AM
Zahir Sholgami