The rest of the code works fine but the ispunct()
function is currently not reading any of the characters, such as a period or exclamation point, it's just counting total characters I am pretty sure. How do I get ispunct()
to calculate the number of characters (.,!) from a text file?
void countChar();
int main() {
ifstream myText("text.txt");
char ch;
if (!myText.is_open()) {
cout << "The input file could not be opened." << endl;
return 1;
}
else {
countChar();
}
}
void countChar() {
ifstream myText("text.txt");
char ch;
int upper = 0, lower = 0, punct = 0;
while (!myText.eof()) {
myText.get(ch);
if (islower(ch)) {
lower++;
} else if (isupper(ch)) {
upper++;
} else (ispunct(ch)); {
punct++;
}
}
myText.close();
cout << "Uppercase characters: " << upper << endl;
cout << "Lowercase characters: " << lower << endl;
cout << "Digits: " << punct << endl;
}
Aucun commentaire:
Enregistrer un commentaire