Count number of white spaces using function - C

Write a C program to accept a line from user and count number of white spaces from the line using function.

Solution:

#include<stdio.h>
int isWhitespace(char c)
{
    if(c == ' ')
        return 1;
    else
        return 0;
}
int main()
{
    char str[100];
    int  W = 0, i;
    printf("Enter String: \n");
    gets(str);
    for(i = 0;str[i] != '\0'; i++)
    {
        W=W+isWhitespace(str[i]);
    }
    printf("\nWhite spaces: %d",W);
    return 0;
}


Output:

count white spaces