我知道如果字符串是指针,你不能在字符串中更改char,但我将字符串初始化为数组,但我现在仍然无法更改字符串:
char temp[50];
FILE * f = fopen ( "123.txt", "r" );
while ( fscanf( f, "%s", temp ) != EOF )
{
temp[2] = " ";
}
fclose(f);
它仍然显示
assignment makes integer from pointer without a cast [-Werror]
我该怎么办?
答案 0 :(得分:1)
这句话:
temp[2] = " ";
正在尝试将字符串分配给单个字符
建议使用:
temp[2] = ' ';
为角色分配角色。
请注意单引号而不是双引号