Hi! All
Here I am trying to write a programme, which will accept a line of text and count the vowels, consonants, digits, whitespaces & others like (.,;,).
The code i am using is :
Code:
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void scan_line(char *line, int *pv, int *pc, int *pd, int *pw, int *po);
void main()
{
char *line;
int vowels=0;
int consonants=0;
int digits=0;
int whitespace=0;
int others=0;
clrscr();
printf("Enter a line of text below : \n");
scanf("%s",line);
printf("%s",line);
scan_line(line,&vowels,&consonants,&digits,&whitespace,&others);
printf("\n No. of vowels: %d",vowels);
printf("\n No. of consonants: %d",consonants);
printf("\n No. of digits: %d",digits);
printf("\n No. of whitespace: %d",whitespace);
printf("\n No. of other characters: %d",others);
getch();
}
void scan_line(char *line, int *pv, int *pc, int *pd, int *pw, int *po)
{
char c;
int count=0;
while((c=toupper(line[count]))!='\n')
{
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
++*pv;
else if(c>='A'&& c<='Z')
++*pc;
else if(c>='0'&& c<='9')
++*pd;
else if(c==' '|| c=='\t')
++*pw;
else
++*po;
++count;
}
return ;
}
But it is not returning the desired result.
Please help Anil.