I got a four * buffer to keep the file reading in binary mode. I know that the length of the file is 70 bytes And this is the value being used to produce the right size buffer. The problem is that, there are 17 or 18 additional spaces in the array, so some random characters are finally added. Can there be a Unicode problem?
The ulFLen stores the file size in bytes and has the correct value (70 files on which I am testing)
/ / to store the file Set a buffer for pcfBuffer = new four [ulFLen]; // Reading the file cout & lt; & Lt; "Input of file ..."; Fstream.seekg (0, ios :: beg); FStream.read (pcfBuffer, ulFLen); If (! FStream.good ()) {cout & lt; & Lt; "FAILED" & lt; & Lt; Endl;} and {cout & lt; & Lt; "SUCCESS" & lt; & Lt; Endl;}
As it is an char array You've probably forgotten a terminal NUL character
In this case it will be correctly:
// Set a buffer to store the file and a terminal NUL character pcfBuffer = new char [ulFLen + 1 ]; // Reading the file cout & lt; & Lt; "Input of file ..."; Fstream.seekg (0, ios :: beg); FStream.read (pcfBuffer, ulFLen); If (! FStream.good ()) {cout & lt; & Lt; "FAILED" & lt; & Lt; Endl;} and {cout & lt; & Lt; "SUCCESS" & lt; & Lt; Addl;} // Add NUL character pcfBuffer [ulFLen] = 0; But note that you only need to end the NUL character for the routine, depending on it, such as string routine or printf Using % s . If you use routines that use the fact that you know the length (70 characters), then it will work without a NUL character too.
Comments
Post a Comment