___________________________Question?__________________________________________________
Write a program that will read a text file and count the number of alphabetic characters (isalpha), digits (isdigits), punctuation characters (ispunctuation), and whitespace (isspace) in the file.
I would appreciate it if anybody can suggest anything.
How would I finish the code I am stuck there are parts missing is there any help somebody can give me???????
The parts that I am not getting is how i can get the program to count the alphanumeric characters, digits, punctuation, and whitespace characters in the file. I don't know exactly what to use for the program to compile correctly. Also, in the else if statement what do I use to count the characters. I think I its similar but I don't know how to write correctly.
__________________________The Code___________________________________________
CODE
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define INPT "proj1.txt"
int main(void)
{
int curCh;
int preCh;
int countCh = 0
int isalpha = 0
int isdigit = 0
int ispunct = 0
int isspace = 0
FILE *fp;
{
//Statement
if (!(fp = fopen(INPT, "r")))
{
printf( "Error opening proj1.txt for reading");
return (1);
} // if open error
while ((curCh = fgetc(fp)) != EOF)
{
else if (curCh
countisalpha ++;
else if
countisdigit++;
else
countispunct++;
else
countisspace++;
preCh = curCh;
}
printf ("The number of alphanumeric characters is: %d\n", countalpha);
printf ("The number of digits is: %d\n", countdigit);
printf ("The number of punctuation characters is: %d\n", countpunct);
printf ("The number of whitespaces is: %d\n", countspace);
flose (fp);
system("PAUSE");
return 0;
}
This post has been edited by colombia23: 20 Jan, 2008 - 04:10 PM