View Code of Problem 58

#include  <stdio.h>
#include  <stdlib.h>
#include  <math.h>
#include  <string.h>

int f(char *s)
{
	int n;
	char *p,b;
	p=s;
	for (n=0,b=0;*p!='\0';p++)
	{
		if(*p!=' ')
		{
			b=1;
		}
		else
		{
			if(b==1)
			{
				n++;
				
			}
			b=0;
		}
	}
	if(b==1) n++;
	return n;
}

int main()
{
	char s[1000];

	while(gets(s)!=NULL)
		printf("%d\n",f(s));
	
	return 0;
	
}

Double click to view unformatted code.


Back to problem 58