I am having trouble reading all content of a single text file into a string. Whenever there is a line break it does not keep the previous strings.
For example if the file contained:
this is stack overflow
and it is cool
The only thing that the string would have after reading the file is " it is cool"
here is the code:
FILE *inputFilePtr;
inputFilePtr = fopen(inputFileName, "r");
char plainText[10000];
// if the file does not exist
if (inputFilePtr == NULL)
{
printf("Could not open file %s", inputFileName);
}
// read the text from the file into a string
while (fgets(plainText, "%s", inputFilePtr))
{
fscanf(inputFilePtr, "%s", plainText);
}
printf("%s\n", plainText);
fclose(inputFilePtr);
Any Help is greatly appreciated!