Free2Code
 
Time: 2008-11-21, 08:18pm
Help me quickly please>>>>>
Subject: Help me quickly please>>>>>  ·  Posted: 2006-12-18, 12:23am
Rank: ? (2)
Member #: 29384
im trying to read a file has many lines but after reading it every time i tried to printf it, but it always print just the last line???/


f = fopen("text.txt","r";
if(!f)
return 1;
while(fgets(s,1000,f) != NULL)
sprintf(value,s);
fclose(f);
printf("%s",value);


 
  Reply to this ·  Post link ·  Top
Subject: Re: Help me quickly please>>>>>  ·  Posted: 2006-12-18, 09:03am
Rank: ? (767)
Member #: 11085
Of course it does. Just logically step through your program.

1) Open the file.
2) If the file is not open, return -1.
3) While 1000 characters from the file are capable of being read in...
3.1) Store the characters in the variable s.
3.2) Take the characters from s and store them in the variable value.
4) Close the file.
5) Print out the contents of the variable value.

Basically, why do you think the variable value holds ever line of the file? You have no instruction that tells it to do so.

- relpats_eht
 
  Reply to this ·  Post link ·  Top
Subject: Re: Help me quickly please>>>>>  ·  Posted: 2006-12-19, 05:23pm
Rank: ? (2)
Member #: 29384
Thank you man i get your idea>>>

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons