Read in your tongue here..

Sunday, October 20, 2013

Finding number of characters, spaces, lower and upper case characters in C++.

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
    char stm[345];
    int l,i,s=0,up=0,lw=0,c;
    cout<<"Enter string:";
    gets(stm);
    l=strlen(stm);
    for(i=0;i<l;i++)
    {
        if(stm[i]==' ')
            s++;
        if(isupper(stm[i]))
           up++;
        if(islower(stm[i]))
           lw++;
    }
    cout<<"Total number of: \nCharacters=";
    cout<<l<<"\nSpaces="<<s<<"\nLower case characters="<<lw<<"\nUpper case characters="<<up;
    getch();
    clrscr();
}

No comments:

Post a Comment