Hi all,
I'm supposed to write a program that counts the number of characters, words, and lines in a text file
++++++++++++++++++++++++++++++++++++++++++++++
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
int main ()
{
ifstream inFile ("file.txt" , ios::in);
if (!inFile){
cerr<<"File could not be opened / Does not exist";
exit (1);
}
char character, word[30];
int letters=0,
words=0,
lines = 0;
while (inFile>>character){
++letters;
if (character == '/n')
++lines;
}
while (!EOF){
inFile>>word;
++words;
}
cout<<"The number of letters in this file -without spaces- are: "<<letters<<endl;
cout<<"The number of lines is: "<<lines<<endl;
cout<<"The number of words is : "<<words<<endl;
return 0;
}
++++++++++++++++++++++++++++++++++++++++++++++
The program does count the letters correctly, but the number of lines and words stay the same, how come?