Allright im working on a new program. I basically need to write something that will read a text file and count the number of alphabetic characters, digits, punctuation characters, and whitespace characters. Then i need to basically report my findings. This is what ive got so far.
Im not sure what exactly to do, it compiles but how do i test it? Do i need to make a file called sp1 in the same directory as the source file? Also in my programming book input is of class int (which is why i put it) but what i dont get is if input is an int then how will input pick up punctuation, whitespace and characters?Code:#include <stdio.h>
#include <stdlib.h>
int main()
{
int alpha = 0;
int digit = 0;
int punct = 0;
int wspace = 0;
FILE* sp1;
int input;
while ((input = fgetc(sp1)) != EOF)
{
if (isalpha(input))
alpha++;
else if (isdigit(input))
digit++;
else if (ispunct(input))
punct++;
else if (isspace(input))
wspace++;
}//while
printf("alphabetic character: %d \n digits: %d \n punctuations: %d \n whitespace characters: %d \n", alpha, digit, punct, wspace);
system("PAUSE");
return 0;
}
Also since i dont know how to test it i dont know if my coding is correct. Feel free to nitpick the coding as well ^^.