Tuesday, 20 October 2015

C program to print total number of spaces in a string

#include<stdio.h>
#include<conio.h>
void main()
{
char name[50],ch=0;
int i=0,scnt=0;
clrscr();
printf("\n enter a name :");
ch=getchar();
    while(ch!='.')
    {
        name[i]=ch;
        i++;
        ch=getchar();
    }
    name[i]='\0';
    printf("\n your name is :");
    i=0;
        while(name[i]!='\0')
        {
            ch=name[i];
                if(ch=='  ')
                    scnt++;
                putchar(ch);
                i++;
        }
printf("\n total no. of spaces in the string=%d",scnt);
getch();
}

No comments:

Post a Comment