#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
rithish
13
Junior Poster in Training
Recommended Answers
Jump to Postscanf()'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().
All 2 Replies
Reply to this topic
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.