Click here to Skip to main content
15,887,135 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Best way to Write and read from a file Pin
fearless stallion23-Feb-06 1:53
fearless stallion23-Feb-06 1:53 
AnswerRe: Best way to Write and read from a file Pin
Dennis Gourjii23-Feb-06 2:56
Dennis Gourjii23-Feb-06 2:56 
JokeRe: Best way to Write and read from a file Pin
James R. Twine23-Feb-06 2:33
James R. Twine23-Feb-06 2:33 
GeneralRe: Best way to Write and read from a file Pin
Dennis Gourjii23-Feb-06 2:50
Dennis Gourjii23-Feb-06 2:50 
JokeRe: Best way to Write and read from a file Pin
James R. Twine23-Feb-06 3:28
James R. Twine23-Feb-06 3:28 
GeneralRe: Best way to Write and read from a file Pin
Dennis Gourjii23-Feb-06 3:45
Dennis Gourjii23-Feb-06 3:45 
AnswerRe: Best way to Write and read from a file Pin
James R. Twine23-Feb-06 4:51
James R. Twine23-Feb-06 4:51 
AnswerRe: Best way to Write and read from a file Pin
Wim Engberts23-Feb-06 5:01
Wim Engberts23-Feb-06 5:01 
You arose quite a discussion! Still, no answer to your original question I believe?
As far as I can see, your code should work just fine, but are you sure that, after changing your structure, you deleted the original file? Could it possibly be that you are reading information that was written with the old structure? In that case, anything could happen!
The problem here is that you simply write a block of data, assuming that it must be what you expect it to be. If you need to be more sure, also after changing the data's structure, you would need to write individual data elements, with some kind of indication as to thei meaning (something like ASN.1, but you could of course write your own simpler version).
If this is no problem to you, then what you are doing now should work. If you simultaneously write from one thread (or application) and read from the other, then the data you read might be corrupted! (imagine one thread being halfway writing a tm structure, while the other is reading it). The best way around this is using simple file-locking.
If you use the CFile method, this would be "CFile::LockRange ()" for example.
If you use the FILE * approach, you will have to use fsopen to open the file, using for example _SH_DENYWR to avoid someone else writing to the file.

Success,
William
GeneralRe: Best way to Write and read from a file Pin
fearless stallion23-Feb-06 19:03
fearless stallion23-Feb-06 19:03 
GeneralRe: Best way to Write and read from a file Pin
Wim Engberts23-Feb-06 23:17
Wim Engberts23-Feb-06 23:17 
GeneralRe: Best way to Write and read from a file Pin
fearless stallion24-Feb-06 1:17
fearless stallion24-Feb-06 1:17 
AnswerRe: ListCtrl Pin
James R. Twine23-Feb-06 4:55
James R. Twine23-Feb-06 4:55 
QuestionOverwriting in the console Pin
Cedric Moonen22-Feb-06 23:59
Cedric Moonen22-Feb-06 23:59 
AnswerRe: Overwriting in the console Pin
divine_augustine8423-Feb-06 0:11
divine_augustine8423-Feb-06 0:11 
GeneralRe: Overwriting in the console Pin
toxcct23-Feb-06 0:13
toxcct23-Feb-06 0:13 
AnswerRe: Overwriting in the console Pin
toxcct23-Feb-06 0:12
toxcct23-Feb-06 0:12 
GeneralRe: Overwriting in the console Pin
Wim Engberts23-Feb-06 0:16
Wim Engberts23-Feb-06 0:16 
GeneralRe: Overwriting in the console Pin
toxcct23-Feb-06 0:17
toxcct23-Feb-06 0:17 
AnswerRe: Overwriting in the console Pin
toxcct23-Feb-06 0:25
toxcct23-Feb-06 0:25 
AnswerRe: Overwriting in the console Pin
Cedric Moonen23-Feb-06 0:49
Cedric Moonen23-Feb-06 0:49 
QuestionPrinting directly without dialog box Pin
LapinGarou22-Feb-06 23:53
LapinGarou22-Feb-06 23:53 
AnswerRe: Printing directly without dialog box Pin
Cool Ju23-Feb-06 0:08
Cool Ju23-Feb-06 0:08 
GeneralRe: Printing directly without dialog box Pin
LapinGarou24-Feb-06 22:49
LapinGarou24-Feb-06 22:49 
QuestionHow to get mac address from specical IP? Pin
Rulala22-Feb-06 23:14
Rulala22-Feb-06 23:14 
QuestionPC/SC in C++ Builder Pin
kittymew22-Feb-06 23:07
kittymew22-Feb-06 23:07 

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.