I'm trying to parse an input file line by line. I want to grab each line one at a time, put it into a null terminated char array. I can't seem to do it.
I tried something like this and just got weird ass results.
int q = 0;
do
{
//if(buffer[i] == )
testFile >> buffer;
q++;
}
while(buffer[q-1] != '\0');
for(int i = 0; i < 80; i++)
{
cout << buffer[i];
}
The buffer is 80 characters and the input file is a test file containing Dorothy Parker's short poem resume'
The code above will put the last word of line 2 into the array and stop there (rest the other 70 odd chars is just junk)I have no clue why. I was under the impression that when the code would encounter a new line it would stop. Does anyone have any suggestions. Please note, I'm not just trying to solve the problem, but also understand what is going on with the code above. Also the input file is 8 lines long.
For fun here's the out put:
damp; p ♠> ╠√" ◄8@ |:> Σⁿ" ♦☺ x☺> └5╠o*<├w ♥☺♥ ⌠√" @♠> ╨;>
where damp; is the only line from the inputfile.