#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

Recommended Answers

All 2 Replies

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().

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.