Here i am trying to read a very big XML file into a char*, but i am getting the following Error:
(Syscall param read(buf) points to unaddressable byte(s))
It is pointing to the line-> size= fread(result,sizeof(char),size,file);
I am using Valgrind for debugging the Segmentation fault. Help are very much appreciated
EDIT: I just ran a test and found out that result is actually pointing to NULL meaning it cannot allocate that much. What am i supposed to do then ?
// Converts XML file to Char*
char* XMLtoString(char* path){
FILE* file;
unsigned long long size;
char* result;
file = fopen(path,"r");
fseek(file,0,SEEK_END);
size = ftell(file);
fseek(file,0,SEEK_SET);
result = (char*)malloc((sizeof(char)*size)+1);
size = fread(result,sizeof(char),size,file);
result[size] = '\0';
fclose(file);
return result;
}