C 主目录中引用的未解析外部符号
我必须创建一个具有函数charster()的程序,该函数接受三个参数:一个字符和两个整数。每y行打印字符输入x次。我得到语法错误LNK2019和LNK1120未解析的外部符号,在main中引用。我知道我做了什么导致了这一点,或者该怎么做来纠正它 这是我的密码:C 主目录中引用的未解析外部符号,c,visual-studio,function,syntax,C,Visual Studio,Function,Syntax,我必须创建一个具有函数charster()的程序,该函数接受三个参数:一个字符和两个整数。每y行打印字符输入x次。我得到语法错误LNK2019和LNK1120未解析的外部符号,在main中引用。我知道我做了什么导致了这一点,或者该怎么做来纠正它 这是我的密码: #include <stdio.h> void charster(char n, int n_char, int n_lines); int main(void) { char n; int n_lines
#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);
}
}
}
#包括
无效字符集(字符n,整数n_字符,整数n_行);
内部主(空)
{
字符n;
int n_行,n_字符;
printf(“请输入要打印的字符、应显示的次数以及应显示的行数:”);
而(扫描频率(“%c,%d,%d”、&n、&n字符、&n行)==3)
{
charster(n,n_chars,n_line);
}
返回0;
无效字符集(字符n,整数n_字符,整数n_行);
{
整数计数;
对于(计数=0;计数
首先,C语言不支持嵌套函数。因此,必须在主函数之外编写函数charster()
您可以将其写在主函数的上方或下方,因为原型已经声明
请查看以下代码:
#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 times;
int lines;
for (lines = 0; lines < n_lines; lines++)
{
for(times=0;times<n_char;times++){
printf("%c ", n);
}
printf("\n");
}
}
#包括
无效字符集(字符n,整数n_字符,整数n_行);
内部主(空)
{
字符n;
int n_行,n_字符;
printf(“请输入要打印的字符、应显示的次数以及应显示的行数:”);
而(scanf(“%c%d%d”、&n、&n字符、&n行)==3)
{
charster(n,n_chars,n_line);
}
返回0;
}
无效字符集(字符n,整数n_字符,整数n_行)
{
整数倍;
内线;
对于(行=0;行 对于(times=0;times首先,C语言不支持嵌套函数。因此,必须在主函数之外编写函数charster()
您可以将其写在主函数的上方或下方,因为原型已经声明
请查看以下代码:
#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 times;
int lines;
for (lines = 0; lines < n_lines; lines++)
{
for(times=0;times<n_char;times++){
printf("%c ", n);
}
printf("\n");
}
}
#包括
无效字符集(字符n,整数n_字符,整数n_行);
内部主(空)
{
字符n;
int n_行,n_字符;
printf(“请输入要打印的字符、应显示的次数以及应显示的行数:”);
而(scanf(“%c%d%d”、&n、&n字符、&n行)==3)
{
charster(n,n_chars,n_line);
}
返回0;
}
无效字符集(字符n,整数n_字符,整数n_行)
{
整数倍;
内线;
对于(行=0;行
对于(times=0;times此代码格式不正确。C不支持嵌套函数定义。因此我应该将函数移到main上方?是。或下方,因为您有一个正确的原型。否,此函数位于main内部。在关闭}main
的
。我缩进了代码以使这一点更加明显。如果您认为函数是独立的,我认为这只是一个输入错误。此代码格式不正确。C不支持嵌套函数定义。因此我应该将函数移到main的上方?是。或者下方,因为您有一个正确的原型。不,此函数位于main.B的内部在关闭main
之前,我已经缩进了代码以使其更加明显。如果您认为函数是独立的,我想这只是一个输入错误。我更正了这一点,现在我在文件范围内找到了一个C2449{(缺少函数头)好吧,我想这只是个错误,我可以让它编译。但是它不会产生任何输出。@Eysaak正在处理它。请再给我一些seconds@Eysaak,请检查我是否已更正scanf()语法和逻辑上也纠正了代码。如果这解决了您的问题,那就太好了。如果您满意,请标记正确的。尝试输入c 2 3I纠正了这一点,现在我在文件范围内找到了一个C2449{(缺少函数头)好吧,我想这只是个错误,我可以让它编译。但是它不会产生任何输出。@Eysaak正在处理它。请再给我一些seconds@Eysaak,请检查我是否已更正scanf()语法和逻辑上修正了代码。如果这解决了您的问题,那就太好了。如果您满意,请标记正确的。尝试输入c 2 3