int main(void)
{
char CurrentChar;
int Spaces = 0;
int NewLines = 0;
int Others = 0;
for(;;)
{
CurrentChar = getchar();
switch(CurrentChar)
{
case '#':
getchar(); //eat the cr
goto Report; //exits the loop
case ' ':
Spaces++;
break;
case '\n':
NewLines++;
break;
default:
Others++;
break;
}
}
Report: //label
printf("\n");
printf("Spaces %d\n", Spaces);
printf("NewLines %d\n", NewLines);
printf("Others %d\n", Others);
getchar();
return 0;
}
No comments:
Post a Comment