[Solved] This cpp code is for loading images using ls command.But it is not loading any image, even though it doesn’t show any error.plz help me to fix this [closed]


There are two major problems with your code. The first is that while (!feof(...)) will not work as you expect it to. That is because the EOF flag is not set until after you try to read beyond the end of the file for the first time. Instead do e.g. while (fgets(...) != NULL).

The second problem, and the probable cause of your problem, is that fgets reads not only the whole line, it also keeps the newline character in the resulting buffer. That means that if you have a line containing the file name hello.jpg it will be stored in the buffer as "hello.jpg\n". You need to check for and remove trailing whitespace from the buffer.

solved This cpp code is for loading images using ls command.But it is not loading any image, even though it doesn’t show any error.plz help me to fix this [closed]