C code
#include <stdio.h>
int main ()
{
int c , nother , new , ndigits [10] , white, tabs ;
for ( int i = 0 ; i< 10 ; i++)
ndigits[i] = 0 ;
while ( (c = getchar() )!= EOF )
{
switch (c)
{
case '0' : case '1' : case '2' :
case '3' : case '4' : case '5' :
case '6' : case '7' : case '8' :
case '9' :
ndigits[c- '0' ]++ ;
break ;
case ' ' :
printf("w"); /*to see how many spaces */
white++ ;
case '\t' :
printf("t");
tabs++;
case '\n' :
printf("n");
new++ ;
break ;
default :
nother++ ;
break ;
}
}
printf ("digits = " ) ;
for ( int i = 0 ; i < 10 ; i++ )
printf ("%d" , ndigits[i]) ;
printf ( ",tabs = %d , new line = %d, spaces = %d , other = %d ",
tabs, white , new , nother );
return 0 ;
}
When I compile it using
GCC
and just pressCtrl + z
it printsdigits = 00000 , tabs = 4200912 , new line = 4194432 , spaces = 2293540 other = 2147307520
where these number come from ?
I compile it again and enter
HELLO HELLO HELLO
and click enter and it printswtnwtnwnn
- why is that (there is 3 n than expected , why it counts three tabs ) ?