#include <stdio.h>
#include <string.h>
struct students{
char name[50];
int age;
int height;
};
int main(int argc, char **argv)
{
struct students manoj;
strcpy(manoj.name, "manojkumar");
manoj.age = 15;
displaymanoj(&manoj); //print testing \n , name , age
return 0;
}
void displaymanoj(struct students *ptr) {
printf("Testing...............DEBUG\n");
printf("%s\t%d\n", ptr->name,ptr->age);
printf("END OF TEST: SUCESS -manoj-");
}我正在学习C,它在使用指针指向结构变量的地方工作。当我运行这个程序时,我得到了正确的输出。只是我的Geany IDE发出了一些信息,我想知道为什么。
我的编译器消息如下:
发布于 2016-08-15 08:41:44
在调用函数之前,必须声明它们。
所以你的程序应该看起来像
// Includes
// Structure
// Function prototype declaration
// This was what you were missing before
void displaymanoj(struct students *ptr);
int main(int argc, char **argv)
{
...
}
void displaymanoj(struct students *ptr) {
...
}发布于 2016-08-15 08:41:45
由于您在从displaymanoj()调用它时没有看到它的定义,所以编译器隐式地声明了一个具有返回类型的int,它与实际的int冲突。请注意,隐式声明已经从C99标准中删除,并且不再有效。
要解决这个问题:
1)将函数displaymanoj()移到main()的定义上,或者
2)做前向申报 of displaymanoj()。
https://stackoverflow.com/questions/38951881
复制相似问题