March 30th, 2003, 08:19 PM
Here is a very simple program that counts words and other things in a document. Some of this code I got help on. I am pretty new to C++ and I was wondering if someone can explain something to me. Here is the code:
int letters = 0, digits = 0, words = 0, puncts = 0, others = 0, average = 0;
cout<< "File not found!!! Exiting...........";
cout<< " File has been successfuly opened!";
while((isspace(ch) || isdigit(ch) || ispunct(ch)) && !txtdoc.eof())
while(isalpha(ch) && !txtdoc.eof())
average = (letters/double(words) + 0.5);
cout<< "Number of letters = " << letters << endl << endl;
cout<< "Number of digits = " << digits << endl << endl;
cout<< "Number of words = " << words << endl << endl;
cout<< "Number of punctuation characters = " << puncts << endl << endl;
My question is : how does it count the words? All I see is
but how does it tell words appart?
My second question is how to do the function of gotoxy (which positions the cursor at a given position on the screen) on dev.?
Thanks in advance;
Last edited by konradj; March 30th, 2003 at 08:28 PM.
March 31st, 2003, 01:27 AM
That's what all the lines of code before and after the code you cited does. Here are some questions for you to consider:
1) What does ch have to be in order to reach the lines you cited?
2) What do the lines after the lines you cited do?
Last edited by 7stud; March 31st, 2003 at 01:30 AM.