Hello,
I've a small program with 4 functions.
The first one reads data from a file and returns it as a string(text_from_file)
Code:
int read_file (char* file_to_open, char* text_from_file){
FILE *fp;
char tmp_str[MAX_STR];
if((fp = fopen(file_to_open, "r"))==NULL) {
printf("Cannot open file.\n");
exit(1);
}
while (!feof(fp)){
fgets(tmp_str,MEGABYTE,fp);
strcat(text_from_file,tmp_str);
}
fclose(fp);
}
Then that string slightly modified and written into a file. When the which I open is a text file, it works well but if I'm opening binary files it doesn't read the whole file, it only reads and returns a smaller string.
What I'm doing wrong? any help would be appreciated