1 #include <stdio.h> 2 int main(void) 3 { 4 int count = 0; 5 char st[5000] = {0}; 6 char *p = NULL; 7 fgets(st,sizeof(st),stdin); 8 for(p = st;*p != ‘\n‘;p++) 9 ; 10 for(;*p != ‘ ‘ && p != st;p--) 11 count++; 12 if(*p == ‘ ‘) 13 count--; 14 printf("%d\n",count); 15 return 0; 16 }
计算字符串最后一个单词的长度,单词以空格隔开。
一行字符串,非空,长度小于5000。
整数N,最后一个单词的长度。
hello world
5
原文:http://www.cnblogs.com/ailx10/p/6287610.html