Sunday, 2 November 2014

to count no. of blank spaces

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char *ptr;
int i=0,k=0;
char str1[20];
cout<<"Enter a string:";
gets(str1);
cout<<endl<<"Original string is:";
puts(str1);
ptr=str1;
for(i=0;*(ptr+i)!='\0';i++)
{
      if( *(ptr+i)==' ' )
      k++;
      else
      cout<<*(ptr+i);
}
cout<<endl<<"Number of blank spaces is:";
cout<<endl<<k;
getch();
}

No comments:

Post a Comment