基本上,程序应该将名称拆分为F和L名称。用户可以将他们的名字与空间组合(例如AlexTank或Alex Tank)。该程序应该读取每个大写字母,并用空格分隔字符串。我遇到的问题是我的程序拆分了名称(识别大写字母),但排除了字符串新输出的大写字母。用C拆分字符串
#include <stdio.h>
#include <string.h>
int main()
{
char name[50], first[25], last[25];
char *pch;
char* key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// ask user for name
printf("What is your name? ");
scanf("%s", name);
printf("Hello \"%s\" here is your First and Last Name:\n", name);
pch = strtok(name, key);
while (pch != NULL)
{
printf("%s\n", pch);
pch = strtok(NULL, key);
}
return 0;
}
你发现了什么问题? – SJuan76
你是否是正则表达式的粉丝,想不出其他的东西? – P0W