以下是我的代码,我试图在Visual Studio中运行它.
#include <stdio.h>
#include <conio.h>
int main()
{
//int i;
//char j = 'g',k= 'c';
struct book
{
char name[10];
char author[10];
int callno;
};
struct book b1 = {"Basic", "there", 550};
display ("Basic", "Basic", 550);
printf("Press any key to coninute..");
getch();
return 0;
}
void display(char *s, char *t, int n)
{
printf("%s %s %d \n", s, t, n);
}
Run Code Online (Sandbox Code Playgroud)
它给出了在键入函数的开括号的行上重新定义的错误.
display在声明之前调用,在这种情况下,编译器假定返回类型为int,但返回类型为void.
在使用之前声明函数:
void display(char *s, char *t, int n);
int main() {
// ...
Run Code Online (Sandbox Code Playgroud)
另请注意,您将其声明为接收char*,但将字符串文字传递给它(const char*)要么更改声明,要么更改参数,例如:
void display(const char *s, const char *t, int n);
int main()
{
// snip
display ("Basic", "Basic", 550);
//snap
}
void display(const char *s, const char *t, int n)
{
printf("%s %s %d \n", s, t, n);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1734 次 |
| 最近记录: |