I want to read a whole text file a once into a single string. I have used the fread() function in the following way:
Code:
#include <stdio.h>
int main()
{
FILE *fInp;
char buffer[1000];
fInp = fopen("input.txt", "r");
fread(buffer, 2, 1000, fInp);
printf("%s", buffer);
getchar();
}
My input.txt is:
Code:
i want to read that into a single string
However it produces a string:
Code:
i want to read that into a single stringĚĚĚĚĚĚĚĚĚ<loads of identical crap>ĚĚĚĚĚĚĚĚĚĚĚĚhűbĚĚĚĚĚĚĚĚHűbĚĚĚĚ«_·=\ű
How to get rid of that crap if i do not know beforehand how many characters are my input.txt?