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. Prob. to catch the EOF ?!

Prob. to catch the EOF ?!

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorialquestion
3 Posts 3 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.
  • F Offline
    F Offline
    Fred D
    wrote on last edited by
    #1

    hi all, in one program i need to extract data from a txt file. the program extracts data line by line, but it doesn't catch the EOF. i included the part of the code that gives me trouble below, if anybody knows how to fix this, let me know! thanx Fred ... char c = 0, *buffer = 0; int nc = 0; while(c != EOF) // !! PROB { if(!ReadFile(hFile, &c, 1, &dwByteRead, NULL)) { AfxMessageBox("Error in ReadFile() : %d", GetLastError()); return NULL; } if(dwByteRead == 1) { if(c == '\r' || c == '\n' || nc >= CHAR_LINE) { szSentence[nc] = 0; return szSentence; } else { szSentence[nc++] = c; } } }

    J J 2 Replies Last reply
    0
    • F Fred D

      hi all, in one program i need to extract data from a txt file. the program extracts data line by line, but it doesn't catch the EOF. i included the part of the code that gives me trouble below, if anybody knows how to fix this, let me know! thanx Fred ... char c = 0, *buffer = 0; int nc = 0; while(c != EOF) // !! PROB { if(!ReadFile(hFile, &c, 1, &dwByteRead, NULL)) { AfxMessageBox("Error in ReadFile() : %d", GetLastError()); return NULL; } if(dwByteRead == 1) { if(c == '\r' || c == '\n' || nc >= CHAR_LINE) { szSentence[nc] = 0; return szSentence; } else { szSentence[nc++] = c; } } }

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      ReadFile does not return any EOF. Instead, it returns TRUE with dwByteRead being 0. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • F Fred D

        hi all, in one program i need to extract data from a txt file. the program extracts data line by line, but it doesn't catch the EOF. i included the part of the code that gives me trouble below, if anybody knows how to fix this, let me know! thanx Fred ... char c = 0, *buffer = 0; int nc = 0; while(c != EOF) // !! PROB { if(!ReadFile(hFile, &c, 1, &dwByteRead, NULL)) { AfxMessageBox("Error in ReadFile() : %d", GetLastError()); return NULL; } if(dwByteRead == 1) { if(c == '\r' || c == '\n' || nc >= CHAR_LINE) { szSentence[nc] = 0; return szSentence; } else { szSentence[nc++] = c; } } }

        J Offline
        J Offline
        Jeremy Falcon
        wrote on last edited by
        #3

        From MSDN on ReadFile().

        the return value is FALSE and GetLastError returns ERROR_HANDLE_EOF
        when the file pointer goes beyond the current end of file.

        So, every time you get to EOF, you're generating what you perceive to be an error. Check for both instead of just the return value. Alternatively, you could use c to check for the value of 46 (0x2E), as that's the ASCII/ANSI EOF char. Jeremy L. Falcon "It's in the mail." Homepage : Sonork = 100.16311
        Surely some striving souls survive symptomatic stress?

        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