I'm on a little project of making a little compressor program. For that I want to read a file, say an .exe, and parse it char by char and use some simple dictionary algorithm to encrypt it.
For reading the file I just thout in using a simple code I found:
char *readFile(char *fileName)
{
FILE *file;
char *code = malloc(10000* sizeof(char));
file = fopen(fileName, "rb");
do
{
*code++ = (char)fgetc(file);
} while(*code != EOF);
return code;
}
My problem is that it's seems imposible to read an .exe or any file at all. When making a printf() of "code" nothing is writen.
What can I do?
@BLUEPIXY well identified a code error. See following. Also you return the end of the string and likely want to return the beginning.
Something to get you started reading any file.
When reading a binary file char-by-char, code typically receives 0 to 255 and EOF, 257 different values.