0

I have a problem. If the text is too long in the text file...the program crashes. How to solve it?

3
Contributors
6
Replies
8
Views
4 Years
Discussion Span
Last Post by WaltP
Featured Replies
  • >I have a problem. If the text is too long in the text file...the program crashes. How to solve it? **IF** the texts inside the text file are within the number of characters to be read in fgets() and is within the length of the array then this is not … Read More

0

if(pFile != NULL){
while(fgets(search,80,pFile) != NULL)
{
if(i==0){
strcpy(string,search);
strcat(string," ");
}
else{
strcat(string,search);
strcat(string," ");
}
i++;
}

I am storing the strings (spaces included) Please help.

1

I have a problem. If the text is too long in the text file...the program crashes. How to solve it?

IF the texts inside the text file are within the number of characters to be read in fgets() and is within the length of the array then this is not the problem,

I am storing the strings (spaces included)

it's already being stored in the string search (line by line with space included)

moreover I cannot reproduce the same problem ,could you post a sample output of the program

0

I tried getting the bytes of the file...and plugged it in the fgets parameter and it worked...now my problem is how to get the file size?

0

and plugged it in the fgets parameter and it worked...now my problem is how to get the file size

I Doubt you need the actual file size for reading every line just make sure that the array size and number of char to be read by fgets is enough for every line

0

When you read using fgets() and the line is longer than the buffer size (or bytes to read) the next read will continue where the last read left off -- in the middle of the line.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.