【发布时间】:2020-01-30 14:25:45
【问题描述】:
我有一个类似的字符串:
my age is 22\r\n\r\n and I live in Rostock
以及其他一些字符串,例如:
I like to swim\r\n\r\n .Yesterday I competed with my 2 friends
现在我想用\r\n\r\n 分割一个字符串并将它与buffer 关联。这是我想要做的:
char buffer[500];
strcpy(buffer, "my age is 22\r\n\r\n and I live in Rostock");
char *p = buffer;
if((p = strchr(p,"\r\n\r\n"))) {
p[strcspn(p,"tock")] = 0; // trying to slice until the end
}
printf("%s", p);
当我尝试编译时,这给了我一个警告,说warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast 我不明白这是什么意思。
还有什么好方法可以将其拆分为 2 个char 缓冲区?
【问题讨论】: