Hi everyone,
I am doing a command line application, which will do two simple things.
1.Write file
2.Read file
I have array of structure like this,
struct MenuDesign
{
int MenuId;
char IdofBit[10];
};
struct MenuDesign objMenu[1000];
Here i am trying to write my structure into text file,using following piece of code.
FILE *MenuFile;
char BufferText[sizeof(objMenu)];
memset(BufferText,0,sizeof(BufferText));
memcpy(BufferText,&objMenu,sizeof(objMenu));
fopen_s(&MenuFile,"D:\\mlkcfg.txt", "w");
fwrite(BufferText,sizeof(struct MenuDesign),1000,MenuFile);
(or)
fwrite(BufferText,sizeof(objMenu),1,MenuFile);
fclose(MenuFile);
I am able to write my structure into file,but while reading i am facing a problem.
Here say i have written 30 records into my text file.I am reading text file with following code.
errno_t error;
char TempBuff[sizeof(objMenu)];
memset(&objMenu,0,sizeof(objMenu));
memset(TempBuff,0,sizeof(TempBuff));
if((error = fopen_s( &MenuDispFile, "D:\\mlkcfg.txt", "r")) ==0)
{
ReadSize = fread(&objMenu,sizeof(struct MenuDesign),1000,MenuDispFile);
(or)
ReadSize = fread(&objMenu,sizeof(objMenu),1,MenuDispFile);
fclose(MenuDispFile);
}
If i put breakpoint and see my structure(after reading file),till 25th record there is no problem,it is reading perfectly.
But from 26th record, it started reading wrong values.
I dont understand, what i am missing here.
Any help is greatly appreciated,
Shiva.
[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]