【发布时间】:2019-11-12 16:18:27
【问题描述】:
我必须创建一个程序,它有一个函数 charster(),它接受三个参数:一个字符和两个整数。它将每 y 行打印字符输入 x 次。我收到语法错误 LNK2019 和 LNK1120 在 main.xml 中引用的未解析的外部符号。并且 IDK 我做了什么导致这个或做什么来纠正它。
这是我的代码:
#include <stdio.h>
void charster(char n, int n_char, int n_lines);
int main(void)
{
char n;
int n_lines, n_chars;
printf("Please enter a character to be printed, the amount of times it should appear, and the amount of lines that should appear: ");
while (scanf("%c, %d, %d", &n, &n_chars, &n_lines) == 3)
{
charster(n, n_chars, n_lines);
}
return 0;
void charster(char n, int n_char, int n_lines);
{
int count;
for (count = 0; count < n_lines; count++)
{
putchar(n);
}
}
}
【问题讨论】:
-
此代码格式错误。 C 不支持嵌套函数定义。
-
所以我应该把函数移到 main 上面?
-
是的。或以下,因为你有一个合适的原型。
-
不,这个函数在main的里面。在
main的关闭}之前。 -
我已经缩进了代码以使这一点更明显。如果您认为该功能是分开的,我想这只是一个错字。
标签: c visual-studio function syntax