题目:计算字符串最后一个单词的长度,单词以空格隔开。
#include <stdio.h>
#include <string.h>
int main()
{
int len, i = 0, n;
char arr[5000];
char* new_a[5000];
char* p;
gets(arr);
p = strtok(arr, " ");
while (p != NULL)
{
new_a[i] = p;
i++;
p = strtok(NULL, " ");
}
n = i;
len = strlen(new_a[n-1]);
printf("%d", len);
return 0;
}