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. csv file problem

csv file problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
15 Posts 2 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.
  • U Offline
    U Offline
    User 589870
    wrote on last edited by
    #1

    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?

    E 1 Reply Last reply
    0
    • U User 589870

      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?

      E Offline
      E Offline
      Eugen Podsypalnikov
      wrote on last edited by
      #2

      Please compare the return values of UINT uiReadBytes = chopChart.Read(..); at the first an secon running and post them here :)

      virtual void BeHappy() = 0;

      U 1 Reply Last reply
      0
      • E Eugen Podsypalnikov

        Please compare the return values of UINT uiReadBytes = chopChart.Read(..); at the first an secon running and post them here :)

        virtual void BeHappy() = 0;

        U Offline
        U Offline
        User 589870
        wrote on last edited by
        #3

        in both cases uireadbytes contains 0.

        E 1 Reply Last reply
        0
        • U User 589870

          in both cases uireadbytes contains 0.

          E Offline
          E Offline
          Eugen Podsypalnikov
          wrote on last edited by
          #4

          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;

          U 1 Reply Last reply
          0
          • E Eugen Podsypalnikov

            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;

            U Offline
            U Offline
            User 589870
            wrote on last edited by
            #5

            actually on saving file at close of application it is inserting end of file after every character.this is actually the problem.

            E 1 Reply Last reply
            0
            • U User 589870

              actually on saving file at close of application it is inserting end of file after every character.this is actually the problem.

              E Offline
              E Offline
              Eugen Podsypalnikov
              wrote on last edited by
              #6

              Please answer, what have you seen at the message boxes ? :)

              virtual void BeHappy() = 0;

              U 1 Reply Last reply
              0
              • E Eugen Podsypalnikov

                Please answer, what have you seen at the message boxes ? :)

                virtual void BeHappy() = 0;

                U Offline
                U Offline
                User 589870
                wrote on last edited by
                #7

                in both cases it is showing count 1024 in messageboxes..my qus is that where is my code inserting EOF after every character?

                E 1 Reply Last reply
                0
                • U User 589870

                  in both cases it is showing count 1024 in messageboxes..my qus is that where is my code inserting EOF after every character?

                  E Offline
                  E Offline
                  Eugen Podsypalnikov
                  wrote on last edited by
                  #8

                  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;

                  U 1 Reply Last reply
                  0
                  • E Eugen Podsypalnikov

                    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;

                    U Offline
                    U Offline
                    User 589870
                    wrote on last edited by
                    #9

                    why my code is inserting EOF after evry character on saving file.where my code is wrong?

                    E 1 Reply Last reply
                    0
                    • U User 589870

                      why my code is inserting EOF after evry character on saving file.where my code is wrong?

                      E Offline
                      E Offline
                      Eugen Podsypalnikov
                      wrote on last edited by
                      #10

                      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;

                      U 1 Reply Last reply
                      0
                      • E Eugen Podsypalnikov

                        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;

                        U Offline
                        U Offline
                        User 589870
                        wrote on last edited by
                        #11

                        yes?but i want to keep the project as unicode

                        E 1 Reply Last reply
                        0
                        • U User 589870

                          yes?but i want to keep the project as unicode

                          E Offline
                          E Offline
                          Eugen Podsypalnikov
                          wrote on last edited by
                          #12

                          :) چرا که نه؟ 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;

                          U 1 Reply Last reply
                          0
                          • E Eugen Podsypalnikov

                            :) چرا که نه؟ 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;

                            U Offline
                            U Offline
                            User 589870
                            wrote on last edited by
                            #13

                            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

                            E 1 Reply Last reply
                            0
                            • U User 589870

                              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

                              E Offline
                              E Offline
                              Eugen Podsypalnikov
                              wrote on last edited by
                              #14

                              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;

                              U 1 Reply Last reply
                              0
                              • E Eugen Podsypalnikov

                                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;

                                U Offline
                                U Offline
                                User 589870
                                wrote on last edited by
                                #15

                                yeah thanx ;)

                                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