c中的函数调用中的参数太多?
too many arguments in function call in c?
我正在尝试创建一个颜色菜单,但最后一行报告了一些错误。
puts("I don't know about the color %c",input);
这是声明
char input[7];
以及初始化
scanf("%c",&input);
错误在这里
Too many arguments in function call
error: expected declaration specifiers or '...' before '&' token
scanf("%c",&input);
^
error: expected declaration specifiers or '...' before string constant
scanf("%c",&input);
^~~~
为什么会这样?
对于初学者来说,这个电话
scanf("%c",&input);
^^^ ^^^
不正确。你必须写
scanf("%s", input);
^^^ ^^^
至于错误信息那么函数puts
只接受一个参数。看来您指的是函数 printf
而不是 puts
。如果要输出整个字符串,格式说明符应为 %s
而不是 %c
。
printf("I don't know about the color %s",input);
^^^
否则,如果您只想输入一个字符而不是字符串,那么您需要编写
scanf("%c",input);
和
printf("I don't know about the color %c\n",input[0]);
关于;
scanf("%c",&input);
对数组的裸引用会降级为数组第一个字节的地址。因此,不需要 &
(并且会导致编译器输出警告消息。这就是您所看到的
关于:
puts("I don't know about the color %c",input);
函数:puts()
只能取单个字符串,无参数。显示 input[]
第一个字符的一种方法是:
printf( "%c\n", input[0] );
我正在尝试创建一个颜色菜单,但最后一行报告了一些错误。
puts("I don't know about the color %c",input);
这是声明
char input[7];
以及初始化
scanf("%c",&input);
错误在这里
Too many arguments in function call
error: expected declaration specifiers or '...' before '&' token
scanf("%c",&input);
^
error: expected declaration specifiers or '...' before string constant
scanf("%c",&input);
^~~~
为什么会这样?
对于初学者来说,这个电话
scanf("%c",&input);
^^^ ^^^
不正确。你必须写
scanf("%s", input);
^^^ ^^^
至于错误信息那么函数puts
只接受一个参数。看来您指的是函数 printf
而不是 puts
。如果要输出整个字符串,格式说明符应为 %s
而不是 %c
。
printf("I don't know about the color %s",input);
^^^
否则,如果您只想输入一个字符而不是字符串,那么您需要编写
scanf("%c",input);
和
printf("I don't know about the color %c\n",input[0]);
关于;
scanf("%c",&input);
对数组的裸引用会降级为数组第一个字节的地址。因此,不需要 &
(并且会导致编译器输出警告消息。这就是您所看到的
关于:
puts("I don't know about the color %c",input);
函数:puts()
只能取单个字符串,无参数。显示 input[]
第一个字符的一种方法是:
printf( "%c\n", input[0] );