The original problem referred to by this thread was fixed, and since then a new problem arose.
Going along with my book, one of the exercises is to make the code that I posted in the first post print the designated file in all lowercase letters (the file reads AAAA\n BBBB\n CCCC\n etc). The problem code that I have now compiles fine, but when run, it ignores the requested number of lines to be printed and instead prints one line every time (the change from capital to lowercase works fine). Here's the code:
Code:
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<ctype.h>
using namespace std;
int main() {
int c, i, lines;
char filename[81], input_line[101];
cout << "Enter a filename and press enter: ";
cin.getline(filename, 80);
ifstream file_in(filename);
if (!file_in) {
cout << "File " << filename << " could not be opened.";
return -1;
}
while (1) {
cout << "Enter number of lines to display, ";
cout << "or press 'Q' and ENTER to quit: ";
cin.getline(input_line, 80);
lines = atoi(input_line);
c = input_line[0];
if (c == 'Q' || c == 'q') {
break;
}
for (i = 0; i < lines; i++) {
file_in.getline(input_line, 100);
for (i = 0; i < (strlen(input_line)); i++) {
input_line[i] = tolower(input_line[i]);
}
cout << input_line << endl;
}
if (file_in.eof()) {
cout << "The end of the file has been reached.";
break;
}
}
cin.get();
return 0;
}
Thanks in advance.