c - 错误 10 错误 C2371 : 'print_plant' : redefinition; different basic types [C]

标签 c

我写了下面的代码:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>

//globals/consts:
#define NAME_SIZE 40
#define COLOR_LEN 20
#define HABITAT_LEN 12
#define LEN 4

//structs:
struct plant
{
    char name[NAME_SIZE];
    int BloomingAreas[3];//0-Not found in this area
    /*
        0=South
        1=Center
        2=North
    */
    char color[COLOR_LEN];
    int habitat[HABITAT_LEN];//0- Not available this month
    int edible;
    //0-Inedible
    //1 Edible
    //2 Unknown
    int protected_plant;
    //0-Unprotected
    //1-Protected
    //2-Unknown
};


int comp(struct plant p1,struct plant p2)
{
    int i;
    int falgHabitat=0;
    int flag=0;
    //BloomingAreas comper:
    if(p1.BloomingAreas[0]!=0 && p2.BloomingAreas[0]!=0)
        flag++;
    else if(p1.BloomingAreas[1]!=0 && p2.BloomingAreas[1]!=0)
        flag++;
    else if(p1.BloomingAreas[2]!=0 && p2.BloomingAreas[2]!=0)
        flag++;


    //Color comper:
    if(strcmp(p1.color,p2.color)==0)
    {
        flag++;
    }
    else if(strcmp(p2.color,"all")==0)
    {
        flag++;
    }

    //Habitat comper:
    for(i=0;i<HABITAT_LEN;i++)
    {
        if(p1.habitat[i]==p2.habitat[i])
        {
            falgHabitat=1;
        }
    }
    if(falgHabitat==1)
    {
        flag++;
    }


    //Edible comper:
    if(p1.edible==p2.edible)
    {
        flag++;
    }

    //protected_plant:
    if(p1.protected_plant==p2.protected_plant)
    {
        flag++;
    }
}
void comparison(struct plant user,struct plant arr[])
{
    int i;
    int flag;
    int temp=0;
    for(i=0;i<LEN;i++)
    {
        flag=comp(user,arr[i]);
        if(flag==1)//Are the same
        {
            printf("According to the statistics there is a chance that this is the plant you're looking for:\n");
            print_plant(arr[i]);
        }
        else
        {
            temp++;
        }
    }
    if(temp==0)
    {
        printf("No results\n");
    }
    getch();
}
void input(struct plant* user)
{
    int i=0;
    int tempInt;
    char temp=NULL;
    int flag=1;
    //BloomingAreas input:
    printf("\n");
    printf("Please enter where you saw the plant:\n");
    printf("Insert 1 choice in south\n");
    printf("Insert 2 choice in central\n");
    printf("Insert 3 choice in north\n");
    printf("Insert ? if you do not remember\n");
    printf("ENTER or any other key to end\n");
    while(flag)//If you inserted a question mark or enter Stop the position input
    {
        temp=getch();
        if(temp=='1')
            user->BloomingAreas[0]=1;
        else if(temp=='2')
            user->BloomingAreas[1]=1;
        else if(temp=='3')
            user->BloomingAreas[2]=1;
        else if(temp=='?')
        {
            user->BloomingAreas[0]=1;
            user->BloomingAreas[1]=1;
            user->BloomingAreas[2]=1;
            flag=0;
        }
        else//Enter or any other key
            flag=0;
    }
    //color input:
    printf("\n");
    (user->color)[0]=NULL;
    (user->color)[1]=NULL;
    printf("Please enter the color of the plant:\n");
    printf("only lowercase letters\n");
    printf("If you do not know insert ?\n");
    scanf("%s", user->color);
    if(user->color[0]=='?')
    {
        user->color[0]=NULL;
        strcpy(user->color,"all");
    }

    //habitat input:
    printf("\n");
    printf("Please enter the numbers of the months you've seen the plant (ENTER to end)\n");
    printf("Enter ? If you do not remember the numbers of the months\n");
    printf("Enter %d to end input\n",HABITAT_LEN+1);
    do{
        scanf("%d",&tempInt);
        if(tempInt=='?')
        {
            for(i=0;i<HABITAT_LEN;i++)
                user->habitat[i]=1;
        }
        else if(tempInt>0 && tempInt<13)
        {
            user->habitat[tempInt-1]=1;
        }
    }while(tempInt!=(HABITAT_LEN+1));

    //edible input:
    printf("\n");
    printf("Do you know for sure that the plant edible?\n");
    printf("(Do not check this if you are not sure!!!)\n");
    printf("Insert the number 1 if the plant is edible\n");
    printf("Insert the number 2 if the plant is't edible\n");
    printf("Insert the number 3 if you do not know\n");
    temp=getch();
    if(temp=='1')
        user->edible=1;
    else if(temp=='2')
        user->edible=0;
    else
        user->edible=2;

    //protected_plant input:
    printf("\n");
    printf("Do you know if this is a protected plant?\n");
    printf("Insert 1 if it is\n");
    printf("Insert 2 if it is not\n");
    printf("Insert 3 if you do not know\n");
    temp=getch();
    if(temp=='1')
        user->protected_plant=1;
    else if(temp=='2')
        user->protected_plant=0;
    else
        user->protected_plant=2;
}
void print_plant (struct plant p)
{
    int i;
    printf("name: %s\n",p.name);
    printf("Blooming areas:\n");
    if(p.BloomingAreas[0]!=0)
        printf("south,");
    if(p.BloomingAreas[1]!=0)
        printf("central,");
    if(p.BloomingAreas[2]!=0)
        printf("North,");
    printf("\d");
    printf("\n");
    printf("color: %s\n", p.color);
    printf("habitat:");
    for(i=0;i<HABITAT_LEN;i++)
    {
        if(p.habitat[i]!=0)
            printf("%3d,",i+1);
    }
    printf("\d");
    printf("\n");

    if(p.edible==0)
    {
        printf("Edible: on\n");
    }
    else 
    {
        printf("Edible: yes\n");
    }

    if(p.protected_plant==0)
    {
        printf("protected plant: no\n");
    }
    else
    {
        printf("protected plant: yes\n");
    }

}
void putInStruct(struct plant arr[])
{
    //plant number 1:
    strcpy(arr[0].name,"Wild Marjoram");
    arr[0].BloomingAreas[2]=1;
    strcpy(arr[0].color,"white");
    arr[0].habitat[3]=1;
    arr[0].habitat[4]=1;
    arr[0].habitat[5]=1;
    arr[0].habitat[6]=1;
    arr[0].habitat[7]=1;
    arr[0].habitat[8]=1;
    //not edible
    //So no need to change anything
    arr[0].protected_plant=1;

    //plant number 2:
    strcpy(arr[1].name,"Aleppo Jerusalem pine");
    arr[1].BloomingAreas[2]=1;
    strcpy(arr[1].color,"green");
    arr[1].habitat[1]=1;
    //not edible
    //So no need to change anything
    arr[1].protected_plant=1;

    //plant number 3:
    strcpy(arr[2].name,"Acacia strap flower");
    arr[2].BloomingAreas[0]=1;
    strcpy(arr[2].color,"red");
    arr[2].habitat[1]=1;
    //not edible
    //So no need to change anything
    //No protected plant so no need to change anything

    //plant number 4:
    strcpy(arr[4].name,"Common fig tree");
    arr[4].BloomingAreas[0]=1;
    arr[4].BloomingAreas[1]=1;
    arr[4].BloomingAreas[2]=1;
    strcpy(arr[3].color,"green");
    arr[3].habitat[2]=1;
    arr[3].habitat[3]=1;
    arr[3].habitat[4]=1;
    arr[3].habitat[5]=1;
    arr[3].edible=1;
    //No protected plant so no need to change anything
}

void zero(struct plant arr[])
{
    int i,j;
    for(i=0;i<LEN;i++)
    {
        for(j=0;j<NAME_SIZE;j++)
            arr[i].name[j]=0;
        for(j=0;j<3;j++)
            arr[i].BloomingAreas[j]=0;
        for(j=0;j<COLOR_LEN;j++)
            arr[i].color[j]=0;
        for(j=0;j<HABITAT_LEN;j++)
            arr[i].habitat[j]=0;
        arr[i].edible=0;
        arr[i].protected_plant=0;
    }
}

int main(void)
{
    struct plant arr[LEN];
    struct plant user;
    zero(arr);
    putInStruct(arr);
    input(&user);
    comparison(user,arr);
}

它给了我以下错误:

Error   10  error C2371: 'print_plant' : redefinition; different basic types    d:\my documents\visual studio 2010\projects\rrr\rrr\dasd.c  205

我该怎么办?

最佳答案

您甚至在声明函数之前就调用了该函数。将 print_plant 的声明移到使用它的代码之上。

关于c - 错误 10 错误 C2371 : 'print_plant' : redefinition; different basic types [C],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23760149/

相关文章:

c - 被误解的话题

c - ICMP主机不可达

php - 如何在ubuntu 14.04上安装php5.6开发扩展

c - 父局部变量充当三个 child 之间的共享变量

c - Scanf 和 printf 返回不同的 unicode 字符

编译器声称指针在未使用时为 const

c - 为数组的动态数组释放内存

c - 返回地址和返回指针的区别

c++ - const关键字在c中是如何工作的

c程序中的cmake和readline库