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

Recommended Answers

All 6 Replies

how did you read the text could you post the code here?

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.

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

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?

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.