我是C的新手,并审查了一些源代码.但我不确定此代码段发生了什么.
我真的不认为它正在做任何事情,因为在调试中输出似乎与tempstr相同.
这就是我的想法,如果我错了就更正.*(tempstr + strlen(line))是将行的长度添加到tempstr并解除引用并将0x0转换为char?
char line[128], tempstr[128]
strcpy(line, "AUTO_ANSWER_CALL = 1");
strcpy(tempstr,line);
*(tempstr + strlen(line)) = (char) 0x0; // Confusing part
Run Code Online (Sandbox Code Playgroud)
Sin*_*nür 12
首先,请注意代码是垃圾.
*(tempstr + strlen(line)) = (char) 0x0;
Run Code Online (Sandbox Code Playgroud)
看起来原作者不太确定是否strcpy复制了终止的nul字符,因此他更加确定而不是检查手册(顺便说一句,strcpy复制终止空值).
这与基本相同:
tempstr[ strlen(line) ] = (char) 0;
Run Code Online (Sandbox Code Playgroud)
char我想,演员阵容就在那里,因为有可能使用C++编译器来编译这段代码.
我不知道为什么
char line[128] = "AUTO_ANSWER_CALL = 1";
Run Code Online (Sandbox Code Playgroud)
是不可接受的.