help with processsing text from fstream getline

Hello,

I am trying to process text received from a fstream getline. I know C well ( and probably have all its bad habits ) but am just learning C++.

I basically want to get a line of text from a file and then remove the space characters so that the array consists of only relevant characters with the final character being a termination character..

For some reason, the while loop gets iterating and does not find the '\0' which I understand the getline function adds...

Any help would be greatly appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

  void getFinalStates(void) {
    int i=0; 
    int j=0; 
    char linebuffer[256]; 
    char finalstates[256]; 
    
    file.getline(linebuffer,'\n'); 
    
    while (linebuffer[i] != '\0') 
      if (linebuffer[i]!= ' ') finalstates[j++] = linebuffer[i++];
      
    return;
}

What happens when linebuffer[i] != '\0' and linebuffer[i] == ' '?

In particular, what happens to i when those conditions are true?
Thank you kindly for your quick response and help ( even though I am feeling like a complete idiot right now :-)

fixed with the following:

while (linebuffer[i] != '\n') {
if (linebuffer[i]!= ' ') finalstates[j++] = linebuffer[i];
i++;
}

I thought it was something weird going on with the fstream object...
Last edited on
Topic archived. No new replies allowed.