Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to remove space while writing data to text file using CFile in vc++ [modified]

how to remove space while writing data to text file using CFile in vc++ [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jadhavjitendrar
    wrote on last edited by
    #1

    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

    A C D 3 Replies Last reply
    0
    • J jadhavjitendrar

      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

      A Offline
      A Offline
      Adam Roderick J
      wrote on last edited by
      #2

      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.

      Величие не Бога может быть недооценена.

      1 Reply Last reply
      0
      • J jadhavjitendrar

        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

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        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]

        J 1 Reply Last reply
        0
        • J jadhavjitendrar

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C CPallini

            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]

            J Offline
            J Offline
            jadhavjitendrar
            wrote on last edited by
            #5

            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..

            C 1 Reply Last reply
            0
            • J jadhavjitendrar

              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..

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              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]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups