#include <iostream>
#include <cstring>
#include <fstream>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
using namespace std;
int main(void)
{
ifstream fin;
ofstream fout;
string filename;
cout << "Welcome\n" << endl;
cout << "This programe will analyze the file content &" << endl;
cout << "compute the statistics of the file you input.\n\n\n\n\n" << endl;
system("pause");
system("cls");
do
{
cout << "Enter input data file name:\n";
cin >> filename;
cout << "\n"; // Get the file name.
fin.open(filename.c_str()); // Convert to C-string and open it.
if (!fin)
{ // Will fail if didn't exist.
cout << "Unable to open " << filename << endl;
cin.get();
system("cls");
}
} while(!fin);
char next;
int characters = 0;
int digits = 0;
int upper = 0;
int lower = 0;
int space = 0;
int eospm = 0;
int others = 0;
while((next = fin.get()) != EOF)
{
//calculate total numbers of characters including space ---> it doesnt count all the characters, what should i use to count every characters including space?
if(isalnum(next))
characters++;
//calculate total numbers of digits ---> correct
if(isdigit(next))
digits++;
//calculate total numbers of uppercase ---> correct
else if(isupper(next))
upper++;
//calculate total numbers of lowercase ---> correct
else if(islower(next))
lower++;
//calculate total numbers of space ---> this 1 doesnt count the correct whitespace either.
else if(isspace(next))
space++;
//calculate total numbers of punctuation ---> correct
else if(ispunct(next))
others++;
}
// Print out what is counted.
cout << "Total Number of Characters: " << characters << endl;
cout << "" << endl;
cout << "Total Number of Uppercase: " << upper << endl;
cout << "Total Number of Lowercase: " << lower << endl;
cout << "Total Number of Digits: " << digits << endl;
cout << "Total Number of Space: " << space << endl;
cout << "Total Number of End-of-Sentence Punctuation Marks: " << eospm << endl;
cout << "Total Number of Other Characters: " << others << endl;
cout << "" << endl;
system("pause");
return 0;
}
alright, here is the problem, for "upper", "lower", "digits" and "other" all displayed correctly,but the others were wrong, i wanted to count all the characters in the file, End-of-Sentence Punctuation Marks( those punct in the end of a sentence ) and the number of white space in between the sentence. the all characters count have a wrong output as well as the whitespace, End-of-Sentence Punctuation Marks have no output. can anyone try on some text file and see where my code went wrong? any help is greatly appreciated. thanks

New Topic/Question
Reply




MultiQuote








|