C programs
C program to return the length of the string, no of vowels, no of characters, no of numerics, no of special characters, no of blank spaces, no of words from a String
Write a c program to return the length of the
string, no of vowels, no of characters, no of numerics, no of special characters,
no of blank spaces, no of words from a String. (assume sentence does not exceed 80 chars).*/
#include<conio.h>
void main()
{
int space=0; int i=0; int lstr=0;
int vow=0; int num=0; int spl=0;
int r;
char s[80];
clrscr();
printf("Enter string:\n\n\t");
gets(s);
while(s[i]!='\0')
{
r = (int)s[i];
if((r>=0&&r<=47) || (r>58 && r<65) || (r>92 && r<97) ||(r>=123 && r<=255))
spl++;
if(s[i]==' ')
space++;
if(s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U')
vow++;
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u')
vow++;
if(isdigit(s[i]))
num++;
//counters
i++;
lstr++;
}
printf("\nThere are %d Space(s)\n",space);
printf("\nThere are %d Word(s)\n",space+1);
printf("\nLength of string is %d\n",lstr);
printf("\nThere are %d vowel(s)\n",vow);
printf("\nThere are %d Numeric character(s)\n",num);
printf("\nThere are %d Special character(s)\n",spl);
getch();
}
/* Output
Output:
Enter the string:deshsan@yahoo.co.in *
Length of string:20
No of Vowels is 7
No of words is 1
No of blankspaces is 1
No of chars is 15
No of Numerics is 0
No of special characters is 4
*/