Click here to Skip to main content
15,927,696 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Determining the exact directory path Pin
Maxwell Chen19-Jun-06 7:28
Maxwell Chen19-Jun-06 7:28 
GeneralRe: Determining the exact directory path Pin
capricious_00119-Jun-06 7:44
capricious_00119-Jun-06 7:44 
AnswerRe: Determining the exact directory path Pin
Michael Dunn19-Jun-06 11:20
sitebuilderMichael Dunn19-Jun-06 11:20 
Questionproblem with reading string from file Pin
Banks K19-Jun-06 5:37
Banks K19-Jun-06 5:37 
AnswerRe: problem with reading string from file Pin
toxcct19-Jun-06 5:41
toxcct19-Jun-06 5:41 
QuestionRe: problem with reading string from file Pin
David Crow19-Jun-06 5:41
David Crow19-Jun-06 5:41 
AnswerRe: problem with reading string from file Pin
Aqueel19-Jun-06 7:56
Aqueel19-Jun-06 7:56 
AnswerRe: problem with reading string from file Pin
Bram van Kampen19-Jun-06 15:04
Bram van Kampen19-Jun-06 15:04 
One Classical way of doing this is to read the string twice! First time you read it, just read it into a buffer of one char, and count the chars.(I assume you want to read a zero terminated string.) In that case, you know you reached the End of the string when you read a 0. At that stage, you have a Character count, which is the size of the string you want to read. Now you can allocate an ample buffer, and read the lot. Simple enough? Yes but No.

Unfortunately, for reasons long since lost in the mist of history, not all characters always consume one byte. Our friends in Japan and China may have a word or two to say about that, but, atleast in their case it is usefull to their language. In the western case, it is a Hangover from the past. The long and short of it is, that the End of a Line in a Text file is recorded as a \r\n two byte sequence. (This is how it is recorded on your Disk).
When you read it back from your disk into a Buffer, the \r is stripped from the file, and all you will find in your buffer is a single \n.

This has important consequences, the main one being that the offset of a character in the buffer is potentially different to the offset of the same position in the File.

There is a way around all this, the translation mechanism depends on how you open the underlaying file.

If you open a file as fopen("File","r") or fopen("File","w")the Library will insert, or delete the \r bytes when reading or writing between buffer and file.


If you open a file as fopen("File","rb") or fopen("File","wb")the Library read or write between buffer and file without translation.

All tends to work well, if you read a file in the same mode it was written by, and if you do not do daft things, such as trying to count chars in a file. Armed with the above knowledge, I suggest you get creative, and do the needed



LateNightsInNewry
QuestionReceiving a Linker Error Pin
capricious_00119-Jun-06 5:15
capricious_00119-Jun-06 5:15 
AnswerRe: Receiving a Linker Error Pin
capricious_00119-Jun-06 5:43
capricious_00119-Jun-06 5:43 
Question_stscanf problems... Pin
kitty519-Jun-06 5:15
kitty519-Jun-06 5:15 
AnswerRe: _stscanf problems... Pin
Viorel.19-Jun-06 5:23
Viorel.19-Jun-06 5:23 
AnswerRe: _stscanf problems... Pin
toxcct19-Jun-06 5:26
toxcct19-Jun-06 5:26 
AnswerRe: _stscanf problems... Pin
James R. Twine19-Jun-06 8:21
James R. Twine19-Jun-06 8:21 
GeneralRe: _stscanf problems... Pin
toxcct19-Jun-06 8:23
toxcct19-Jun-06 8:23 
AnswerRe: _stscanf problems... Pin
James R. Twine19-Jun-06 8:52
James R. Twine19-Jun-06 8:52 
GeneralRe: _stscanf problems... Pin
Zac Howland19-Jun-06 9:44
Zac Howland19-Jun-06 9:44 
AnswerRe: _stscanf problems... Pin
James R. Twine19-Jun-06 14:48
James R. Twine19-Jun-06 14:48 
GeneralRe: _stscanf problems... Pin
Zac Howland19-Jun-06 15:49
Zac Howland19-Jun-06 15:49 
JokeRe: _stscanf problems... Pin
James R. Twine19-Jun-06 15:56
James R. Twine19-Jun-06 15:56 
AnswerRe: _stscanf problems... Pin
Zac Howland19-Jun-06 5:46
Zac Howland19-Jun-06 5:46 
GeneralRe: _stscanf problems... Pin
kitty519-Jun-06 6:09
kitty519-Jun-06 6:09 
Questionsubclassing PropertySheets and PropertyPages Pin
camoguard19-Jun-06 5:10
camoguard19-Jun-06 5:10 
AnswerRe: subclassing PropertySheets and PropertyPages Pin
cje19-Jun-06 7:48
cje19-Jun-06 7:48 
GeneralRe: subclassing PropertySheets and PropertyPages Pin
camoguard19-Jun-06 8:28
camoguard19-Jun-06 8:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.