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. ReadFile and reading a single line of text

ReadFile and reading a single line of text

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 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.
  • P Offline
    P Offline
    Paolo Ponzano
    wrote on last edited by
    #1

    hello, I'm porting some old code from C to Windows code, I'm in a little trouble, suppose I've got a text file, I need to copy single line of text into a listview, before I did something like FILE *fMMC=fopen(filename,"r"); . . . while(!feof(fMMC)) { while (fgets(buffer,BUFFER_SIZE,fMMC)) { ....insert buffer into listview } } now porting to Windows code, I did someting as HANDLE fMMC=CreateFiles(..all_the_parameters)... while(true) { DWORD br; ReadFile(fMMC, buffer, 255, &BR, NULL)) break; } my question is : in buffer, I can have multiple lines, since with fgets it takes a whole line and stop, with ReadFile I can have 2/3/4 lines depending of each lenght, how do I can retrieve from buffer only 1 line at time? is there a simple way? so that if buffer is composed of 3 lines, i get 3 item in listview Thanks in advance Paolo p.s. if it's possible in some way to copy only a line as fgets does, it would be much more better, thanks again

    D 1 Reply Last reply
    0
    • P Paolo Ponzano

      hello, I'm porting some old code from C to Windows code, I'm in a little trouble, suppose I've got a text file, I need to copy single line of text into a listview, before I did something like FILE *fMMC=fopen(filename,"r"); . . . while(!feof(fMMC)) { while (fgets(buffer,BUFFER_SIZE,fMMC)) { ....insert buffer into listview } } now porting to Windows code, I did someting as HANDLE fMMC=CreateFiles(..all_the_parameters)... while(true) { DWORD br; ReadFile(fMMC, buffer, 255, &BR, NULL)) break; } my question is : in buffer, I can have multiple lines, since with fgets it takes a whole line and stop, with ReadFile I can have 2/3/4 lines depending of each lenght, how do I can retrieve from buffer only 1 line at time? is there a simple way? so that if buffer is composed of 3 lines, i get 3 item in listview Thanks in advance Paolo p.s. if it's possible in some way to copy only a line as fgets does, it would be much more better, thanks again

      D Offline
      D Offline
      darkbyte
      wrote on last edited by
      #2

      You have to parse the text yourself. If you feel the file will always be small, then i suggest you load it completely in 1 pass, then parse that memory chunk. Otherwise, you need to parse a little differently and take care not only of \n but also of when you reached the end of the buffer and have to reload another segment. Hope this gives you a hint.

      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