-5

I have tried to reading a text file but the array stores only the last line of the text file.

    char cleanedText[10000]={'\0'};
    while(!feof(fileptr))
      {
        fgets(cleanedText, 10000 , fileptr);
      }

But,the cleanedText stores only the last sentence which is written in the text line.

For example these two is written in the text,

asdasdasd

thisisus

When i print the cleanedText.

The screen just shows thisisus.

What is the problem?

realr
  • 3,652
  • 6
  • 23
  • 34
ambtscdr
  • 3
  • 2
  • 1
    The code you've posted doesn't output anything. See [mcve]. – user3386109 Aug 10 '19 at 00:11
  • 4
    You will want to look at [**Why is while ( !feof (file) ) always wrong?**](https://stackoverflow.com/questions/5431941/why-is-while-feoffile-always-wrong) That is mitigated somewhat by your use of `fgets` in the loop, but I suspect you have more than just `fgets` there... – David C. Rankin Aug 10 '19 at 00:11
  • 1
    Possible duplicate of [Why is “while (!feof(file))” always wrong?](https://stackoverflow.com/questions/5431941/why-is-while-feoffile-always-wrong) – lost_in_the_source Aug 10 '19 at 01:09

1 Answers1

1

Each call to fgets writes into the same place, overwriting what was there previously.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101