Can't read the file when adding '\n' to it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
				fseek(f1, 0, SEEK_END);
				long Size = ftell(f1);
				rewind(f1);
				
				buffer=(char*) malloc(Size);
				if(buffer==NULL){
					cout <<"Memory allocation has failed!");
					return 0;
				}

				size_t result = fread(buffer, 1, Size, f1);
				if(result!=Size){
					cout << "Error while reading the file!";
					return 0;
				}

Could someone tell me why this code works well if there is no break line in the txt file but when I write '\n' to a text file it gives me the error: "Error while reading the file!". I've been trying to figure it out for a longer while now but it nothing really makes sense to me...
How did you open the file with fopen. "r" (text) or "rb" (binary). This effects what ftell returns for the actual file length.

http://www.cplusplus.com/reference/clibrary/cstdio/ftell/
Thank you very much, I've changed it and it works now fine!
Topic archived. No new replies allowed.