Count the word which ends with 's' character in C++ using file handling


#include <conio.h>
#include <fstream.h>

void couts(char c[])
{
    int i=0;
    int cnt=0;
    while(c[i+1]!='\0')
    {
if(c[i]=='s' && c[i+1]==' ')
{ cnt++; }
i++;
    }
    if(c[i]=='s')
    { cnt++;}
    cout<<cnt;
}

void main ()
{
char c[]="hellos world hows are yous";
char *p;
ifstream ifs("abc.txt",ios::in);
ifs.getline(p,27);
clrscr();
       couts(p);
getch();
}

No comments

Post your comments

Powered by Blogger.