複数の単語を含む1行のテキストを入力し、最も長い単語の長さを見つけます.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void main()
{
	char text[1000];
	int maxValue=0;
	int value=0;
	printf("       :
"); gets(text); int length=strlen(text); for(int i=0;i<length+1;i++) { if(isalpha(text[i])) { value++; } else { if(value > maxValue) { maxValue=value; } value=0; } } printf(" :%d
",maxValue); }
 
 
  2
 
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
	char str[100];
	int max=0;
	int count=0;
	printf("      :");
	gets(str);
	for(unsigned int i=0;i<strlen(str);i++)
	{
		if(str[i]>='A'&&str[i]<='Z')
		{
			count++;
		}
		else if(str[i]>='a'&&str[i]<='z')
		{ 
			count++;
		}
		else
		{
			if(max<count)
			{
				max=count;
			}
			count=0;
		}
	}
	printf("         :%d
",count); }
  3
#include <stdio.h>
#define N 81
void main()
{
	char string[N];
	int i,m=0,word=1,t=0,n;
	char c;
	gets(string);
	for(i=0;(c=string[i])!='\0';++i)
	{
		if(c==' ')
		{
			n=0;
			word=1;
		}
		else if(n==0)
		{
			word++;
			m=word-1;
			if(m>t)
			{
				t=m;
			}
		}
	}
	printf("t=%d
",t); }
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM 1000
void main()
{
	char str[NUM];
	int i=0,n=0,max=0,j;
	gets(str);
	j=strlen(str);
	do
	{
		if(str[i]!=' ')
		{
			n++;
		}
		else
		{
			if(n>max)
			{
				max=n;
			}
			n=0;
		}
		if(i==j-1)
		{
			if(n>max)
			{
				max=n;
			}
		}
		i++;
	}while(i<j);
	printf("there is %d letters in the longest word.
",max); }