我已经编写了以下C代码来更新字符数组rb,但它打印出垃圾值。
限制条件是我们不能使用任何其他库。那么该怎么解决呢?
#include <stdio.h>
void update(char* buff){
char word[] = "HII_O";
buff = word;
return;
}
int main(){
char rb[6];
update(rb);
rb[5] = '\0';
printf("[%s]\n",rb);
return 0;
}
限制条件是我们不能使用任何其他库。那么该怎么解决呢?
word
复制到buf
中,即:strcpy(buf, word)
。 - mediocrevegetable1strcpy
函数非常简单。您只需要在其位置放置一个for
循环,并逐个字符将word
复制到buff
中。 - mediocrevegetable1buff[0] = word[0]; buf[1] = word[1];
等等。 - kaylum