Pages

Sunday, October 7, 2012

A program that read a line of text and display number of upper case, lower case, digit, space and other characters

 This code is written on  Turbo c Compailer..
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main() 

charst[100]; 
inti,l,upper=0,lower=0,digit=0,space=0,other=0; 

clrscr(); 
printf("Enter any line: "); 
gets(st); 

   l=strlen(st); 
for (i=0; i<l; i++) 
if (st[i]>='a' &&st[i]<='z') 
lower++; 
else if (st[i]>='A' &&st[i]<='Z') 
upper++; 
else if (st[i]>='0' &&st[i]<='9') 
digit++; 
else if (st[i]==' ') 
space++; 
else
other++; 

printf("\nUpper= %d",upper); 
printf("\nLower= %d",lower); 
printf("\nDigit= %d",digit); 
printf("\nSpace= %d",space); 
printf("\nOther= %d",other); 
getch(); 



No comments:

Post a Comment