csv file problem
-
hi, i m reading data of csv file in a char buffer like this CFile shopCart(strFileName,CFile::modeRead); char buff[5000]={0}; shopCart.Read(buff,sizeof(buff)); and then saving changes before closing application in this way. CFile::Remove(strFileName); CFile csvFile(strFileName,CFile::modeWrite |CFile::modeCreate ); strCSV = L"|" + strCSV+ char(13) + char(10); csvFile.Write(strCSV,strCSV.GetLength()*sizeof(TCHAR)); problem is that at first exec buffer holds data of all the file but after closing and re exec buffer contains only one character of file even though file contains same data after updation.wat can be the problem may b?
-
hi, i m reading data of csv file in a char buffer like this CFile shopCart(strFileName,CFile::modeRead); char buff[5000]={0}; shopCart.Read(buff,sizeof(buff)); and then saving changes before closing application in this way. CFile::Remove(strFileName); CFile csvFile(strFileName,CFile::modeWrite |CFile::modeCreate ); strCSV = L"|" + strCSV+ char(13) + char(10); csvFile.Write(strCSV,strCSV.GetLength()*sizeof(TCHAR)); problem is that at first exec buffer holds data of all the file but after closing and re exec buffer contains only one character of file even though file contains same data after updation.wat can be the problem may b?
Please compare the return values of
UINT uiReadBytes = chopChart.Read(..);
at the first an secon running and post them here :)virtual void BeHappy() = 0;
-
Please compare the return values of
UINT uiReadBytes = chopChart.Read(..);
at the first an secon running and post them here :)virtual void BeHappy() = 0;
in both cases uireadbytes contains 0.
-
in both cases uireadbytes contains 0.
Try it :) :
{
...
CFile cFile;
if (cFile.Open(strFileName, CFile::modeRead)) {
BYTE byBuffer[1024] = {0};
UINT uiReadBytes = cFile.Read(byBuffer, sizeof(byBuffer));
CString cszMessage;
cszMessage.Format(_T("File: %s:\r\nCount of read bytes = %u"),
strFileName, uiReadBytes);
AfxMessageBox(cszMessage);
cFile.Close();
}
...
}virtual void BeHappy() = 0;
-
Try it :) :
{
...
CFile cFile;
if (cFile.Open(strFileName, CFile::modeRead)) {
BYTE byBuffer[1024] = {0};
UINT uiReadBytes = cFile.Read(byBuffer, sizeof(byBuffer));
CString cszMessage;
cszMessage.Format(_T("File: %s:\r\nCount of read bytes = %u"),
strFileName, uiReadBytes);
AfxMessageBox(cszMessage);
cFile.Close();
}
...
}virtual void BeHappy() = 0;
actually on saving file at close of application it is inserting end of file after every character.this is actually the problem.
-
actually on saving file at close of application it is inserting end of file after every character.this is actually the problem.
Please answer, what have you seen at the message boxes ? :)
virtual void BeHappy() = 0;
-
Please answer, what have you seen at the message boxes ? :)
virtual void BeHappy() = 0;
in both cases it is showing count 1024 in messageboxes..my qus is that where is my code inserting EOF after every character?
-
in both cases it is showing count 1024 in messageboxes..my qus is that where is my code inserting EOF after every character?
Good, the file can be read in the both cases :) What is your next step (wish) please ? :) Would you like to read and write an UNICODE or ANSI csv-file ? :)
virtual void BeHappy() = 0;
-
Good, the file can be read in the both cases :) What is your next step (wish) please ? :) Would you like to read and write an UNICODE or ANSI csv-file ? :)
virtual void BeHappy() = 0;
why my code is inserting EOF after evry character on saving file.where my code is wrong?
-
why my code is inserting EOF after evry character on saving file.where my code is wrong?
When your project is configured as UNICODE project the output will be performed by two bytes per character... Would you like to see your output in ANSI ? :)
virtual void BeHappy() = 0;
-
When your project is configured as UNICODE project the output will be performed by two bytes per character... Would you like to see your output in ANSI ? :)
virtual void BeHappy() = 0;
yes?but i want to keep the project as unicode
-
yes?but i want to keep the project as unicode
:) چرا که نه؟ Just convert your string to ANSI sequence:
#include <AtlConv.h>
...
{
...
USES_CONVERSION;
LPSTR lpszANSI = T2A(cszOut);
cOutFile.Write(lpszANSI, strlen(lpszANSI));
...
}virtual void BeHappy() = 0;
-
:) چرا که نه؟ Just convert your string to ANSI sequence:
#include <AtlConv.h>
...
{
...
USES_CONVERSION;
LPSTR lpszANSI = T2A(cszOut);
cOutFile.Write(lpszANSI, strlen(lpszANSI));
...
}virtual void BeHappy() = 0;
thanx a lot Eugen Podsypalnikov that was what the problem was actually it was inserting extra byte.thanx nw it is working fine after converting to ansi. Regards
-
thanx a lot Eugen Podsypalnikov that was what the problem was actually it was inserting extra byte.thanx nw it is working fine after converting to ansi. Regards
You are welcome ! (sometimes I do read and write UNICODE csv-files, you could it too, when it will be needed once :) )
virtual void BeHappy() = 0;
-
You are welcome ! (sometimes I do read and write UNICODE csv-files, you could it too, when it will be needed once :) )
virtual void BeHappy() = 0;
yeah thanx ;)