Hi this is my first post here...
I am learning C right now(through the book on the Title), so my knowledge about the language is very small...
So, in the first chapter of the book there is a programm about tables, which counts how many times every digit, every "white" space(" ","\n" etc) and other "letters" appear in a text.
So I wrote down the code exactly as in the book:
Code:
#include<stdio.h>
main()
{
int c,i,nwhite,nother;
int ndigit[ 10];
nwhite = nother=0;
for (i=0 ; i<10 ; ++i)
ndigit[i]=0;
while((getchar()) !=EOF)
if (c>='0' && c<='9')
++ndigit[c-'0'];
else
if (c==' ' || c=='\n' || c=='\t')
++nwhite;
else
++nother;
printf("Ta psifia einai");
for( i = 0 ; i < 10 ; ++i)
printf("%d",ndigit[i]);
printf(",ta leyka diastimata einai %d, kai oi alloi xaraktires %d", nwhite, nother);
printf(".Sas eyxaristoume pou mas kalesate.\n");
}
According to the book when I run the programm, I should take something like that:
digits 9300000001
white spaces 124
other 330
----------------
Now my problem:
I get always digits: 0000000000
white spaces 0
and other: the number of the characters in the text...
no matter what text I use...
------------------
I would be very glad if someone could find the error...
Thanks a lot,
plutonas