Jump to content

trying to read from a file?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
hallinan

hallinan

    Newbie

  • Members
  • Pip
  • 4 posts
I'm trying to read from a file which contains customers First name,last name, address and last transaction number.
Can anyone help I'm going to use this for searching for a customer. This is what I have so far!!

[HIGHLIGHT="C"]
main()
{
FILE *fptr;
char *filename = "index";

char Fname[20];
char Lname[20];
char Address[80];
int lastTrans;



fptr=fopen(filename,"r");

while(!feof(fptr))
{
fscanf(fptr,"%s%s%s%d",&Fname,&Lname,&Address,&lastTrans);
printf("%s %s\t%s\t%d",Fname,Lname,Address,lastTrans);
}

return 0;
}

[/HIGHLIGHT]

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,720 posts
That should work, provided the file path is correct. You forgot to put fclose(fptr) before the return statement, though. What problem are you having?