我正在尝试将 PIN(PIN 中有数据)复制到 temp。 (假设 PIN 总是小于 temp)
const char * PIN;
....
char [10] temp ="";
int i = 0;
while (*(PIN+i)) {
temp[i] = (PIN+i)*;
i++;
}
如果我把 temp 当作指针来处理也可以吗?
long int res = strtol (&temp, NULL, 10);
最佳答案
不!
PIN+i
不会改变任何状态。当 PIN
加上 i
不等于 0 时为真。因为 PIN
是一个随机内存地址,所以这是个坏主意。
如果要复制字符串,请查看strcpy
。
关于c - 这会在复制字符串时起作用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9074422/