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. fread error in Console application

fread error in Console application

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
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.
  • A Offline
    A Offline
    Anu_Bala
    wrote on last edited by
    #1

    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

    N R D 3 Replies Last reply
    0
    • A Anu_Bala

      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

      N Offline
      N Offline
      namaskaaram
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0
      • A Anu_Bala

        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

        R Offline
        R Offline
        Rajkumar R
        wrote on last edited by
        #3

        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.

        A 1 Reply Last reply
        0
        • R Rajkumar R

          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.

          A Offline
          A Offline
          Anu_Bala
          wrote on last edited by
          #4

          We tried "rb" to open the file. But no use. It just read very few datas.

          Anu

          R 1 Reply Last reply
          0
          • A Anu_Bala

            We tried "rb" to open the file. But no use. It just read very few datas.

            Anu

            R Offline
            R Offline
            Rajkumar R
            wrote on last edited by
            #5

            check what is the error, using ferror, _get_errno

            1 Reply Last reply
            0
            • A Anu_Bala

              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

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

              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

              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