Jump to content
  • Advertisement
Sign in to follow this  
y2jsave

integer file

This topic is 3779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

there is a txt file of integers . while reading the file by fscanf(file*,"%d") , how to detect end of file .i tried using EOF or null but it is not working help please thanks

Share this post


Link to post
Share on other sites
Advertisement
Have you been checking the return value from fprintf()? Can we have some sample code please?

Share this post


Link to post
Share on other sites
code is here

FILE *fin;
int count=0;
fin=fopen(FILE_name,"r");
while(fscanf(fin,"%d")!=EOF)
{
count++;
}

fclose(fin);

Share this post


Link to post
Share on other sites
Quote:
.i tried using EOF or null but it is not working


How?

Does it run in endless loop? Does it crash? Does it not read correct number of values?

Share this post


Link to post
Share on other sites
This might work.

FILE *fin;
int count=0;
int value;

fin=fopen(FILE_name,"r");
if (fin) {
while ( fscanf(fin, "%d", &value) != EOF ) count++;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
This might work.

FILE *fin;
int count=0;
int value;

fin=fopen(FILE_name,"r");
if (fin) {
while ( fscanf(fin, "%d", &value) != EOF ) count++;
}



no, it is facing same problem ............


is a file size of 2307 kb too big for this program to handle??????????

Share this post


Link to post
Share on other sites
Quote:
Original post by y2jsave
also it is giving a warning
out of memory allocating 86044 bytes


Then show the code where this happens. The file reading code you've shown doesn't allocate any memory.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!