“分配使指针从整数变成整数而没有强制转换"分别将char分配给数组时 [英] "assignment makes integer from pointer without a cast" when assigning chars to arrays individually
问题描述
我很难知道将字符分配给该数组之间的区别.我在全球宣布
I'm having some trouble knowing the difference between assigning chars to this array. I globally declared
char charlist[7];
然后执行函数
int stringthing()
{
for(int i=0; i < 7; i++)
{
charlist[i] = 'G';
}
return 0;
}
,然后在main中声明它.当我使用for循环分配值时,它工作正常,但是当我使用
and then declare it in main. It works fine when I assign values with the for loop, but when I use
int stringthing()
{
charlist[0] = "M";
charlist[1] = "T";
charlist[2] = "W";
charlist[3] = "R";
charlist[4] = "F";
charlist[5] = "S";
charlist[6] = "U";
return 0;
}
并在main中声明此错误,出现错误赋值使指针从整数变为无强制转换[默认启用]".这是同一件事吗?
and declare this in main, I get the error "assignment makes integer from pointer without a cast [enabled by default]". It's this the same thing?
推荐答案
尝试将第二个示例中的引号从双引号更改为单引号.现在,您正在尝试将每个数组元素设置为字符串而不是字符.
Try changing the quotes in your second example from double-quotes to single-quotes. Right now you're trying to set each array element to a string rather than a character.
这篇关于“分配使指针从整数变成整数而没有强制转换"分别将char分配给数组时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!