如何更改字符串中的char

时间:2017-09-16 20:06:09

标签: c

我知道如果字符串是指针,你不能在字符串中更改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]

我该怎么办?

1 个答案:

答案 0 :(得分:1)

这句话:

temp[2] = " ";

正在尝试将字符串分配给单个字符

建议使用:

temp[2] = ' ';

为角色分配角色。

请注意单引号而不是双引号