hi there experts, i am unable to read from a file using this function. this program is part of a library management project in C so here is the update books function. Code: void books_update(struct books book[1000],struct book_size n) { int ctr=0; int asg = (n.total_books); FILE *in; in = fopen("INPUT.txt","r"); if(in == NULL) return; while( fscanf(in,"%s%s%s%c%d\n",&(book[asg].subject) ,&(book[asg].title) ,&(book[asg].author) ,&(book[asg].type) ,&(book[asg].available) ) == 5 ) { asg++; ctr++; printf("i am reading\n"); } n.total_books = asg; printf("\t\t\nall ARTICLES Updated Successfully...\n"); printf("--> Number of Articles added in this update %d.\n",ctr); printf("--> Total No. of Articles in the library %d.\n\n",(n.total_books)); e.g format of book/cd in INPUT.txt mystery sherlock_holmes conan_doyle b 1 info c_for_dummies unknown c 1
sorry but i get no error. its just not reading in the values. when i print or use the structure's strings i get (null). so how? please help thanks............ after scanning still the print says --> Number of Articles added in this update 0 they always give 0.
What is the value of asg? (Suggestion: put a printf in that displays the *actual* value. Do not answer this with what you *think* asg is.) By the way your function doesn't fclose(in). It should, otherwise you will leak handles and eventually will not be able to open any files.