Page 60 - Programming Microcontrollers in C
P. 60
Program Flow and Control 45
{
int na=0,ne=0,ni=0,no=0,nu=0;
int nother=0,c;
while ((c=getchar())!=EOF)
if(c==’A’ || c==’a’)
na=na+1;
else if(c==’E’ || c==’e’)
ne=ne+1;
else if(c==’I’ || c==’i’)
ni=ni+1;
else if(c==’O’ || c==’o’)
no=no+1;
else if(c==’U’ || c==’u’)
nu=nu+1;
else
nother=nother+1;
printf( “As=%d, Es=%d, Is=%d, Os=%d, Us=%d and”
“ Others=%d\n”,na,ne,ni,no,nu,nother);
return 0;
}
This program shows several new features of C. The first is found in
the program lines
int na=0,ne=0,ni=0,no=0,nu=0;
int nother=0,c;
When the variables na and so forth are defined, they are assigned
initial values of 0. Such an initialization is always possible when
variables are defined. The next statement of the program is
while ((c=getchar())!=EOF)
if(c==’A’ || c==’a’)
na=na+1;
else if(c==’E’ || c==’e’)
ne=ne+1;
else if(c==’I’ || c==’i’)
ni=ni+1;
else if(c==’O’ || c==’o’)
no=no+1;
else if(c==’U’ || c==’u’)