1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include<iostream>
#include<cctype>
#include<fstream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
struct Count
{
int countChars; //Counts characters
int countNW; //counts nonwhite spaces
int countAlpha; //counts # of alphabetical letters in use
int countDigits; //counts digits
int countPunctuation; //counts punctuation
};
int countChars(Count&);
int countNW(Count&);
int countAlpha(Count&);
int countDigits(Count&);
int countPunctuation(Count&);
int main()
{
string Total_Character;
string Alphabetic_Character;
string Punctuation;
int i; //repeater
ifstream input;
ofstream output;
string fname;
//Intro
cout << "Welcome to this program.\n";
cout << "Please enter text file you use.\n";
cin >> fname;
//opening file if correct
input.open(fname.c_str());
if(input.fail())
{
cout << "Not a valid filename\n";
exit(0);
}
char line[80]; //number of lines in the file being read
char delims[]= ",\t\n"; // delimeters: space, ',', tab, return
while(fgets(line,256,fp))
{
printf("lines %d\n", line);
countChars(Count, line);
countNW(Count, line);
countAlpha(Count, line);
countDigits(Count, line);
countPunctuation(Count, line);
}
}
/* Function: countChars
* Input: characters
* Output:Counts letters on the line
* Description: Counts letters in each line
*/
int countChar(Counts& Count, char line[])
{
int c=0; //Repeater
char letter; //each individual letters in the line
while(line[c] != "\0")
{
input >> letter;
c++
}
return c;
}
/* Function: countNW
* Input:Spaces and returns
* Output: Count the number of non white spaces
* Description: Counts number of non white spaces
*/
int countNW(Counts& countNW, int line[])
{
int d=0; //Repeater
char
while(line[d] != "\0")
{
input >>
/* Function: countAplha
* Input:Alphabetical charachters
* Output:Counts the number of alphabetical characters
* Description:
*/
int countAlpha(Counts& countAlpha, int line[])
{
int e=0; //Repeater
char
while(line[e] != "\0")
{
input >>
/* Function: countDigits
* Input:numbers
* Output:Counts the number of numbers usage
*/
int countDigits(Counts& countDigits, int line[])
{
int f=0; //
char
while(line[f] != "\0"
{
input >>
/* Function: countPunctuation
* Input:Punctuations
* Output:
*/
int countPunctuations(Count& countPunctuation, int line[])
{
int g=0; //repeater
char
while (line[g] != "\0"
{
input >>
// 1.Does not print out accurate total character count
// 2.Does not print out accurate alphabetic character count
// 3.Does not print out accurate numeric character count
// 4.Does not print out accurate punctuation count
// 5.Does not print out accurate non whitespace character count
|