fread error in Console application
-
I use FILE to read datas from file.But it does not read full datas. For Ex: if my file have 9 datas it reads only 6 datas then it jumped out from the loop. when i see the YCS file.. it contains 9 datas, so no problem in writing. Problem only in reading data. THis is my code...Whats the problem???Pls help me. void ReadThermodata() { char FPath[] = "C:\\SelCompLst.YCS"; FILE *fp; SThermoData pData; if((fp = fopen((LPCTSTR)FPath,"r"))==NULL) { return; } int cnt = 0; while( fread( &pData, sizeof( struct SThermoData ), 1 ,fp ) ) { ThermoDataList.push_back(pData); cnt = cnt + 1; } }
Anu
-
I use FILE to read datas from file.But it does not read full datas. For Ex: if my file have 9 datas it reads only 6 datas then it jumped out from the loop. when i see the YCS file.. it contains 9 datas, so no problem in writing. Problem only in reading data. THis is my code...Whats the problem???Pls help me. void ReadThermodata() { char FPath[] = "C:\\SelCompLst.YCS"; FILE *fp; SThermoData pData; if((fp = fopen((LPCTSTR)FPath,"r"))==NULL) { return; } int cnt = 0; while( fread( &pData, sizeof( struct SThermoData ), 1 ,fp ) ) { ThermoDataList.push_back(pData); cnt = cnt + 1; } }
Anu
This is just a wild guess, try opening the file in "r+b" mode... when the file is opened in text mode,there is possibility for the file to stop at ascii values like 26.... Hope this helps!
-
I use FILE to read datas from file.But it does not read full datas. For Ex: if my file have 9 datas it reads only 6 datas then it jumped out from the loop. when i see the YCS file.. it contains 9 datas, so no problem in writing. Problem only in reading data. THis is my code...Whats the problem???Pls help me. void ReadThermodata() { char FPath[] = "C:\\SelCompLst.YCS"; FILE *fp; SThermoData pData; if((fp = fopen((LPCTSTR)FPath,"r"))==NULL) { return; } int cnt = 0; while( fread( &pData, sizeof( struct SThermoData ), 1 ,fp ) ) { ThermoDataList.push_back(pData); cnt = cnt + 1; } }
Anu
it seems its a binary mode data file, you need to open it with "rb", some value of data in binary mode is EOF in text mode.
-
it seems its a binary mode data file, you need to open it with "rb", some value of data in binary mode is EOF in text mode.
-
check what is the error, using ferror, _get_errno
-
I use FILE to read datas from file.But it does not read full datas. For Ex: if my file have 9 datas it reads only 6 datas then it jumped out from the loop. when i see the YCS file.. it contains 9 datas, so no problem in writing. Problem only in reading data. THis is my code...Whats the problem???Pls help me. void ReadThermodata() { char FPath[] = "C:\\SelCompLst.YCS"; FILE *fp; SThermoData pData; if((fp = fopen((LPCTSTR)FPath,"r"))==NULL) { return; } int cnt = 0; while( fread( &pData, sizeof( struct SThermoData ), 1 ,fp ) ) { ThermoDataList.push_back(pData); cnt = cnt + 1; } }
Anu
Anu_Bala wrote:
Whats the problem???Pls help me.
Have you bothered to use the debugger to step through the code?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne