READ different datatypes from file.

jose_peeterson's Avatar, Join Date: May 2011
Contributor
Hi experts,
my following program is SUPPOSED TO read in following contents from INPUT.txt file

Code:
mystery sherlock_holmes conan_doyle b 0 1
jokes what_a_gag jose_johnson b 0 1
magazines expat alan b 0 1
comics archies archies b 0 1
comedy tom_and_jerry c 0 1
my upload.c program
Code:
#include<stdio.h>
#include<string.h>
#include<math.h>


struct books
{
 char title[100];
 char author[50];
 char subject[50];
 char type;
 int borrower; // 0 no one borrowed
 int available;

};

struct size
{
 int total_books;
 int t_m;

};

void upload(struct books book[1000] ,struct size n);

int main()
{
 struct size n;
 struct size book[1000];
 
 upload(book,n);


return 0;
}


void upload(struct books book[1000] ,struct size n)
{

int i=0;

FILE *f;

f = fopen("INPUT.txt","r");

 if(f == NULL)
  {
  printf("\n\tERROR : UNable to open file....\n"); 
  return;
  }

while( (i < 4) && (fscanf(f,"%s%s%s%c%d%d\n",&(book[i].subject),&(book[i].title),&(book[i].author),&(book[i].type),&(book[i].borrower),&(book[i].available) ) == 6))
{
 i++;
printf("%s %s %s %c %d %d\n",  (book[i].subject),(book[i].title),(book[i].author),(book[i].type),(book[i].borrower),(book[i].available) );
}

fclose(f);

return;
}
it does not print out the read data, so can you help me please.
there is also a warning for upload(book,n); -- integer to pointer or something like that
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Have another look at line 2 of main().
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Also have a quick look at what you do to i between the fscanf and the printf. That might have something to do with it. You get no output by the way because the while expression immediately evaluates FALSE; this is because fscanf doesn't return 6.