It is a program to find out number of vowels, consonants, digits and whitespaces in a string to be input by the user. After compilation and during running fgets part is skipped. When I use scanf, the program works fine except that I can't input whitespace. Where does the problem lie? Please explain elaborately ( I am a newbie :-P) and possible remedies.
#include<stdio.h>
#include<string.h>
void main()
{
/*Getting the input*/
printf("How much long is your string?: ");
int n;
scanf("%d",&n);
int i,j,vowels=0,consonants=0,spaces=0,digits=0,actual_length;
char k, str[n+1];
printf("Please enter your string: ");
fgets(str,n+1,stdin);
actual_length=strlen(str);
/*Actual computation*/
for(i=0;i<actual_length;i++)
{
if(str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
vowels++;
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
vowels++;
if(str[i]==32)
spaces++;
for(j='0';j<='9';j++)
{
if(str[i]==j)
digits++;
}
for(k='A';k<='Z';k++)
{
if(k!='A'&&k!='E'&&k!='I'&&k!='O'&&k!='U')
{
if(str[i]==k)
consonants++;
}
}
for(k='a';k<='z';k++)
{
if(k!='a'&&k!='e'&&k!='i'&&k!='o'&&k!='u')
{
if(str[i]==k)
consonants++;
}
}
}
printf("The number of vowels are %d, number of consonants are %d, number of digits are %d and number of white spaces are %d\n",vowels,consonants,digits,spaces);
}