Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   READ different datatypes from file. (http://www.go4expert.com/forums/read-datatypes-file-t26403/)

jose_peeterson 29Jul2011 20:57

READ different datatypes from file.
 
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 30Jul2011 17:06

Re: READ different datatypes from file.
 
Have another look at line 2 of main().

xpi0t0s 30Jul2011 17:15

Re: READ different datatypes from file.
 
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.


All times are GMT +5.5. The time now is 04:37.