无法修改char数组 [英] Cannot modify char array
本文介绍了无法修改char数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑以下代码.
char message[]="foo";
void main(void){
message[] = "bar";
}
为什么MPLAB IDE v8.63中存在语法错误?我只是想更改字符数组的值.
Why is there a syntax error in MPLAB IDE v8.63? I am just trying to change the value of character array.
推荐答案
声明后不能使用像这样的字符数组.如果要为字符数组分配新值,可以这样:-
You cannot use character array like that after declaration. If you want to assign new value to your character array, you can do it like this: -
strcpy(message, "bar");
这篇关于无法修改char数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文