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