<分区>
我是初学者 C 程序员。最近我一直在尝试练习在 C 中使用字符串函数。
因此,我编写了以下程序:
消息检测器.c
#include <stdio.h>
#include <string.h>
int main(void)
{
char a[100] = "Alex:HeyGoodMorning!:1911hrs:0:1012:2017:::";
char *p = strtok(a,":");
char n[20];
int i = 1;
while(p != NULL) {
strcpy(n,p);
p = strtok(NULL,":"); //limit to characters before semi-colon
i++;
if (i = 2) { //after 2 occurrences of the semi-colon. print a string
printf("%s\n",n);
break;
}
}
return 0;
}
我的程序输出如下:
Alex
但是,我希望程序能够输出
HeyGoodMorning!
我应该对上面的程序做哪些修改?非常感谢您的帮助