What is the best way to read a file in C?
I have heard of using fread but then how do you find the size of the file?
This is my example code but it seems to have odd errors.
I have heard of using fread but then how do you find the size of the file?
This is my example code but it seems to have odd errors.
Code:
char * read(char * filename){
FILE * fo;
fo = fopen(filename, "r");
if(fo){
char * buffer = NULL;
size_t result;
int length;
length = file_length(fo);
result = fread(buffer,1,length,fo);
fclose(fo);
return buffer;
} else {
fclose(fo);
return NULL;
}
}
Comment