我正在使用适用于 Windows 的 Pelles 编译器。 我有两个错误
#2168: Operands of '&' have incompatible types 'char *' and 'char *'.
#2140: Type error in argument 1 to 'scanf'; expected 'const char * restrict' but found 'int'.
我的代码看起来像
#include <stdio.h>
static char herp[20];
int main()
{
int a;
a = 2;
printf("Some random number %d\n" ,a);
scanf("Input: %c" &herp);
getchar();
return 0;
}
scanf 似乎有很多问题,所以我不知道为什么。我对 C 很陌生,到目前为止我很喜欢它。我们将不胜感激。
最佳答案
scanf("Input: %c" &herp);
缺少一个逗号:
scanf("Input: %c", &herp);
由于 herp
是一个字符数组,因此您应该指定要写入的字符,例如
scanf("Input: %c", &herp[0]); // to write to the first character.
如果您输入字符串,则可以省略 &
:
scanf("Input: %s", herp);
关于C#2140 : Type error in argument 1 to 'scanf' ; expected 'const char * restrict' but found 'int' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15714339/