I do not know exactly what the standard input file is. I told the program to open "stdin".... this is where my problem is I think.
I think the rest of the code should work.
This code compiles but does not run. I get a "Segmentation error." Don't know what that is exactly.
#include <stdio.h>
int main(void)
{
int digit_cnt = 0, other_cnt = 0, c;
FILE *f;
f = fopen("stdin", "r");
while ((c = fgetc(f)) != EOF)
if (c >= '0' && c <= '9')
++digit_cnt;
else if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' ||
c == ' ' || c == '\n')
++other_cnt;
printf("%10s%10s\n", "digits", "other");
printf("%10d%10d\n", digit_cnt, other_cnt);
fclose(f);
return 0;
}
This post has been edited by KiddKoder: 30 October 2010 - 09:41 PM

New Topic/Question
Reply



MultiQuote





|