我创建了一个非常简单的代码,但是它不起作用!我只想创建一个包含字符串的数组。但是,必须将这些字符串放在不带字符字符方法的位置。换一种说法:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char wstr[20][10];
int i;
for (i=0;i<20;i++)
wstr[i]='BA';
return 0;
}
但编译器向我显示警告和错误:
[Error] incompatible types when assigning to type 'char[10]' from type 'int'
[Warning] multi-character character constant [-Wmultichar]
我该怎么办?
for (i=0;i<20;i++)
strcpy(wstr[i], "BA");
单引号表示单个字符;单引号表示单个字符。字符串文字使用双引号。该strcpy()
调用确保您以后可以修改值,因为修改字符串文字本身是未定义的行为。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句