int main()
{
char str[128];
char buf[128];
printf ("please input the string you want to split:\n");
fgets (str,sizeof(str),stdin);//allow input the space
str[strlen(str)-1] = '\0';//deal with the '\n'
char *result;
result = strtok (str, ":");//split the string according ":"
strcpy (buf, str);//copy string
printf ("result1 = %s\n",result);
result = strtok (NULL, ":");
printf ("result2 = %s\n",result);
char name[]={"谁啊"};
strncat (buf,name,3);//add the first to three to buf from name
printf ("buf:%s\n",buf);
return 0;
}
{
char str[128];
char buf[128];
printf ("please input the string you want to split:\n");
fgets (str,sizeof(str),stdin);//allow input the space
str[strlen(str)-1] = '\0';//deal with the '\n'
char *result;
result = strtok (str, ":");//split the string according ":"
strcpy (buf, str);//copy string
printf ("result1 = %s\n",result);
result = strtok (NULL, ":");
printf ("result2 = %s\n",result);
char name[]={"谁啊"};
strncat (buf,name,3);//add the first to three to buf from name
printf ("buf:%s\n",buf);
return 0;
}