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<cstdio>
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
}Counts;
int readChars(ifstream&, Count[]);
int countChars(Count&, char line[]);
int countNW(Count&, char line[]);
int countAlpha(Count&, char line[]);
int countDigits(Count&, char line[]);
int countPunctuation(Count&, char line[]);
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);
cout << "Not a valid filename\n";
exit(0);
}
char line[256]; //number of lines in the file being read
char delims[]= ",\t\n"; // delimeters: space, ',', tab, return
while (input.getline(line, 256))
{
cout << "lines, line";
countChars(Counts, line);
countNW(Counts, line);
countAlpha(Counts, line);
countDigits(Counts, line);
countPunctuation(Counts, line);
}
}
/* Function: countChars
* Input: characters
* Output:Counts letters on the line
* Description: Counts letters in each line
*/
int countChar(Count& countChar, int line[])
{
int c=0; //Repeater
char letter; //each individual letters in the line
while(line[c] != '\0')
{
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(Count& CountNW, int line[])
{
int d=0; //Repeater
while(line[d] != '\0')
{
d++;
}
}
/* Function: countAplha
* Input:Alphabetical characters
* Output:Counts the number of alphabetical characters
* Description:
*/
int countAlpha(Count& countAlpha, int line[])
{
int e=0; //Repeater
while(line[e] != '\0')
{
e++;
}
}
/* Function: countDigits
* Input:numbers
* Output:Counts the number of numbers usage
*/
int countDigits(Count& countDigits, int line[])
{
int f=0;
while (line[f] != '\0')
{
f++;
}
return 0;
}
/* Function: countPunctuation
* Input:Punctuations
* Output:
*/
int countPunctuations(Count& countPunctuation, int line[])
{
int g=0; //repeater
while (line[g] != '\0')
{
g++;
}
}
|