Read in your tongue here..

Sunday, October 20, 2013

Calculating total number of words and lines in a string using C++.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
    char stm[100];
    cout<<"Enter string:";
    gets(stm);
    int i,s=0,l=0;
    for(i=0;stm[i]!=NULL;i++)
    {
        if(stm[i]==' ')
            s++;
        if(stm[i]=='.')
            l++;
    }
    cout<<"Total number of:\nWords="<<s+1<<"\nLines="<<l;
    getch();
    clrscr();
}

No comments:

Post a Comment