Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my VC++ code;

Process A write a record to a file and process B read the same record of file.
The record structure is like as follows:

struct IDX_HeaderLayout{


char today[8];
char logfile_seq[4];
char log_seq[6];
int start_no;
int end_no;
ULONGLONG current_logsize;
ULONGLONG current_idxsize;
int process_run[3];
int process_link[3];
int last_sdata_no[3]; // <----- This point
char last_time[3][12];
char crlf[2];
}

Very strange event occur that;
When A process write a record to a file and B process read it, but the value of record fields - especially last_data_no fields - are different between two processes.
This is my first experience during my career.
I have checked the source code, structure and file system, directory ... but failed to find the what point of causes....

Please help or advise me.

Thank you in advance.

What I have tried:

One day wasted my today.But failed. I dont know anything now....
Posted
Updated 16-Jul-17 23:13pm
Comments
OriginalGriff 17-Jul-17 4:56am    
How does A write it, how doers B read it, and how can you tell it's different?

1 solution

This is a continuation of your earlier question: Making file in PC, but broken records[^]. Writing a fixed length structure should just work (assuming you do it correctly). And reading it back the same. I already suggested that since this is a binary file, the addition of the CR?F sequence at the end of each resord serves no purpose. All you need is something like:
C++
// to write a single record
fwrite(&logRecord, sizeof(logRecord), 1, handle);

// to read a record
fread(&logRecord, sizeof(logRecord), 1, handle);

Ensure that you call fclose after writing all records.
 
Share this answer
 
Comments
Member 12330615 19-Jul-17 20:47pm    
Omitting size parameter in the use of sprintf_s has no compile error, but make running error.
char a[8];
sprintf(a, "%07d", i); // this has no compile error. but it cause strange result.
Richard MacCutchan 20-Jul-17 4:06am    
And you want me to guess what "it cause strange result" means?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900