2016-08-15 62 views
0
#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发出了一些我想知道为什么的消息。53:6:警告:函数冲突类型

我的编译器的消息如下:

回答

2

您必须称他们之前声明的功能。

所以,你的程序应该是这个样子

// 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) { 
    ... 
} 
1

既然你的displaymanoj()定义当你从main()调用它是没有看到,编译器隐式声明一个返回类型为int 与实际冲突一。请注意,自C99标准以来,隐式声明已被删除且不再有效。

为了修正它:

1)无论是移动上述主要的()的定义或
2功能displaymanoj())执行displaymanoj()forward declaration

+0

是的,我已经通过上面的主要声明来解决它。什么是'implcit声明'的实际意义 – ManojKumar

+0

我是16,并且是新的c编程 – ManojKumar

+1

当编译器第一次看到一个函数,并且如果它还没有看到该函数的声明,那么编译器会隐式声明一个'int'作为返回类型。这被称为隐式函数声明,因为编译器会为你做。这是C99之前的旧规则。在C99中,这条规则已被删除,现在所有函数都需要声明(定义也提供声明 - 这就是移动main()函数上面的函数的原理)。 –