Issue with fgetc handling CR + LF

Apparantly, fgetc(file) will return an occurance of consecutive CR + LF as LF, discarding the CR. Since I am trying to make a file compression program I'd rather get byte by byte, without any exceptions. How can this be worked around?
Open the file as binary and use fread/fwrite.
Last edited on
Sorry, but you'll have to give me much more information on that. How do I open a file as binary as you say? I figured out some code via google, but the compiler does not like it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <sys/stat.h>

// [...]

struct stat results;

if (stat(lTemp, &results) != 0) {
	printf_s("Error: Cannot read file size.\n");
	return end();
}

long lLength = results.st_size;

ifstream lFile(lTemp, ios::in | ios::binary); // error C2078: too many initializers
char * lS = (char*)malloc(sizeof(char) * lLength);
if(!lFile.read(lS, lLength)) { // error C2228: left of '.read' must have class/struct/union
	printf_s("Error: Error reading file.\n");
	return end();
}
lFile.close(); // error C2228: left of '.close' must have class/struct/union 


lTemp is a char[256] with the name of the file to be opened.

Thanks for any help in advance.
1
2
3
#include <iostream>
#include <fstream>
using namespace std;

You're missing those.
You don't need to call close, the destructor does that for you.

Meaningful variable names go a long way to understanding your own code.

You'll never fit all files into memory, it's best to just go with a fixed size buffer, 2 - 32K is typical.

return end(); doesn't make sense in this context.
Topic archived. No new replies allowed.