Yes, I have this kind of problems because it was always hard for me to follow the pointers operations. So, I have this simple code:
struct myfile {
char* name;
char* content;
long size;
};
myfile this_file;
int main() {
read();
return 0;
}
void read() {
output("Please, specify file name: ");
cin >> (this_file.name = new char);
FILE *stream;
stream = fopen(code.name, "r");
if (stream != NULL) {
fseek(stream , 0, SEEK_END);
myfile.size = ftell(codefile);
myfile.content = new char[myfile.size];
fseek(myfile, 0, SEEK_SET);
if ((fread(myfile.content, 1, myfile.size, stream)) == 0) {
fclose(codefile);
cout << "File is empty!\n");
}
}
}
It gets the name of the file correctly, it gets the size of the content but when trying to allocate space to the content
member the program crashes, which I know is some pointers issue, but, as always, can't remember/figure out what is it. It crashes when reaching this line: myfile.content = new char[myfile.size];
I need your help again. Thanks!