我在尽我所能去理解memchr函数,但有一些简单输出的问题。我在* newchar的末尾添加了额外的字符。memchr返回意外字符
#include <stdio.h>
#include <string.h>
int main() {
char plus[6] = "12+123";
char *newchar = (char*) memchr(plus,43,3);
printf("%s",newchar);
}
输出:
+123('
我有望获得 “+123”,为什么它给我多余的字符?我注意到输出是一致的,这让我更早感到困惑,它似乎并不是从内存中随机取出的,而是由memchr函数引起的。
请记住,在C字符串是真的叫***空值终止字符串***。 –
你不需要演员表 –
你为什么用'43'而不是''+''? –