How to read lines of text from file and put them into an array

Try specifying the last argument as ‘\n’ in both getline() functions:

getline(myfile, line1[a], '\n');

instead of

getline(myfile, line1[a], ' ');

Leave a Comment