Contact Learn C
Copy

Program 85:To Print number of white spaces in sentence

Program 85:
 
#include<stdio.h>
#include<string.h>
main()
{
    int i,spaces=0;
    char str[100];
    printf("Enter a sentence to know number of white spaces\n");
    gets(str);
    for(i=0;i<strlen(str);i++)
    {
        if(str[i]==' ')
        {
            spaces++;
        }
    }
    printf("%d\n",spaces);

}
Explanation:

This is same as the
Program 82:To count number of times a letter repeated in sentence except here we are calculating number of times a space is repeated.
Output:

To Print number of white spaces in sentence
Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide