Your reading loop will read all lines, but will discard all but the last line:
//read all lines in file and write in 'buf'
while(file.getline(buf,255,'\n'));
This is because the getline
call just overwrites the contents in buf
, it does not append.
Instead do something like
//read all lines in file and append to 'text'
while(file.getline(buf,255,'\n'))
text += buf;