how to remove space while writing data to text file using CFile in vc++ [modified]
-
plz help me.This is my code CFile cTestFile; cTestFile.Open(_T("D:\\Jitu.txt"),CFile::modeCreate | CFile::modeReadWrite); CArchive ar(&cTestFile,CArchive::store); m_pRecordSet = new CDaoRecordset(m_pDatabase); CString strQuery = _T("SELECT * FROM pdpstate ORDER BY pdpstate.setid"); m_pRecordSet->Open(dbOpenDynaset,strQuery,0); int nRecordCnt = m_pRecordSet->GetRecordCount(); int nFieldCnt = m_pRecordSet->GetFieldCount(); int ntemp = 8; COleVariant variantTemp; for(int nCnt = 0; nCnt < nRecordCnt; nCnt++) { for(int nfCnt = 0; nfCnt < nFieldCnt; nfCnt ++) { variantTemp.Clear(); variantTemp = m_pRecordSet->GetFieldValue(nfCnt ); CString csSetID; csSetID.Format(_T("%d"),variantTemp.intVal); cTestFile.Write(csSetID,sizeof(csSetID)); cTestFile.Write(_T(","),1); } } cTestFile.Close(); Raj
modified on Thursday, September 10, 2009 11:23 PM
-
plz help me.This is my code CFile cTestFile; cTestFile.Open(_T("D:\\Jitu.txt"),CFile::modeCreate | CFile::modeReadWrite); CArchive ar(&cTestFile,CArchive::store); m_pRecordSet = new CDaoRecordset(m_pDatabase); CString strQuery = _T("SELECT * FROM pdpstate ORDER BY pdpstate.setid"); m_pRecordSet->Open(dbOpenDynaset,strQuery,0); int nRecordCnt = m_pRecordSet->GetRecordCount(); int nFieldCnt = m_pRecordSet->GetFieldCount(); int ntemp = 8; COleVariant variantTemp; for(int nCnt = 0; nCnt < nRecordCnt; nCnt++) { for(int nfCnt = 0; nfCnt < nFieldCnt; nfCnt ++) { variantTemp.Clear(); variantTemp = m_pRecordSet->GetFieldValue(nfCnt ); CString csSetID; csSetID.Format(_T("%d"),variantTemp.intVal); cTestFile.Write(csSetID,sizeof(csSetID)); cTestFile.Write(_T(","),1); } } cTestFile.Close(); Raj
modified on Thursday, September 10, 2009 11:23 PM
Actually if you want remove all spaces, then one solution is :- 1. Just open the file in write mode and read all the content of the file in a CStringArray line by line using CArchive. 2. Before setting the content to CStringArray, just use the CString ::Remove function to remove the space. 3. Delete the current file. 4. Create a new file and write the CStringArray content to the new file.
Величие не Бога может быть недооценена.
-
plz help me.This is my code CFile cTestFile; cTestFile.Open(_T("D:\\Jitu.txt"),CFile::modeCreate | CFile::modeReadWrite); CArchive ar(&cTestFile,CArchive::store); m_pRecordSet = new CDaoRecordset(m_pDatabase); CString strQuery = _T("SELECT * FROM pdpstate ORDER BY pdpstate.setid"); m_pRecordSet->Open(dbOpenDynaset,strQuery,0); int nRecordCnt = m_pRecordSet->GetRecordCount(); int nFieldCnt = m_pRecordSet->GetFieldCount(); int ntemp = 8; COleVariant variantTemp; for(int nCnt = 0; nCnt < nRecordCnt; nCnt++) { for(int nfCnt = 0; nfCnt < nFieldCnt; nfCnt ++) { variantTemp.Clear(); variantTemp = m_pRecordSet->GetFieldValue(nfCnt ); CString csSetID; csSetID.Format(_T("%d"),variantTemp.intVal); cTestFile.Write(csSetID,sizeof(csSetID)); cTestFile.Write(_T(","),1); } } cTestFile.Close(); Raj
modified on Thursday, September 10, 2009 11:23 PM
jadhavjitendrar wrote:
cTestFile.Write(csSetID,sizeof(csSetID));
What is the purpose of the above line? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
plz help me.This is my code CFile cTestFile; cTestFile.Open(_T("D:\\Jitu.txt"),CFile::modeCreate | CFile::modeReadWrite); CArchive ar(&cTestFile,CArchive::store); m_pRecordSet = new CDaoRecordset(m_pDatabase); CString strQuery = _T("SELECT * FROM pdpstate ORDER BY pdpstate.setid"); m_pRecordSet->Open(dbOpenDynaset,strQuery,0); int nRecordCnt = m_pRecordSet->GetRecordCount(); int nFieldCnt = m_pRecordSet->GetFieldCount(); int ntemp = 8; COleVariant variantTemp; for(int nCnt = 0; nCnt < nRecordCnt; nCnt++) { for(int nfCnt = 0; nfCnt < nFieldCnt; nfCnt ++) { variantTemp.Clear(); variantTemp = m_pRecordSet->GetFieldValue(nfCnt ); CString csSetID; csSetID.Format(_T("%d"),variantTemp.intVal); cTestFile.Write(csSetID,sizeof(csSetID)); cTestFile.Write(_T(","),1); } } cTestFile.Close(); Raj
modified on Thursday, September 10, 2009 11:23 PM
jadhavjitendrar wrote:
for(int nCnt = 0; nCnt < nRecordCnt; nCnt++) { for(int nCnt = 0; nCnt < nFieldCnt; nCnt++)
The inner and outer loop should use different variables.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
jadhavjitendrar wrote:
cTestFile.Write(csSetID,sizeof(csSetID));
What is the purpose of the above line? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Thanks for reply.. Actually this line is used for writing data to text file.bcoz i m reading data from mdb file and writing it into text file so that purpose this line is used..So plz give me solution ,it's urgent..
-
Thanks for reply.. Actually this line is used for writing data to text file.bcoz i m reading data from mdb file and writing it into text file so that purpose this line is used..So plz give me solution ,it's urgent..
The line is wrong: you should replace it with
cTestFile.Write(csSetID, csSetID.GetLength() * sizeof(TCHAR));
Anyway, I doubt this is what you really want to do (i.e. Are you trying to write a wide-char text file?)?
jadhavjitendrar wrote:
So plz give me solution ,it's urgent..
I recall you one of the implicit mechanism of this forum: "urgentz requests go directly inside the recycle bin". :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]