0
#include <stdio.h>
#include <stdlib.h>
void main()
{
    char a[100];
    int i,c=0;
    printf("enter the text: ");
    scanf("%20s",a);
    for(i=0;a[i]!='\0';i++)
    {
        if(a[i]==32)
        {
            c++;
        }
    }
    printf("number of spaces in text is %d",c);
}
 ascii value of space is 32 but it shows o spaces in output
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by rithish
1

scanf()'s %s specifier doesn't read whitespace, that's the delimiter. Since you learned not to use gets(), the proper replacement is fgets(), not scanf().

Edited by deceptikon

-1

ooh so thanks deceptikon i got the correct output so ur solved threads wil be going to be 162

Edited by rithish

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.