警告:从不兼容的指针类型“node_t *

问题描述 投票:0回答:1

我正在使用链表并尝试将列表(node_t)中节点的信息分配给单独的结构(list_stats_t)

struct node
{
    char firstName[50], lastName[50], major[50], classStanding[50];
    bday bd;     // this struct just contains int values of day, month, and year

    struct node* next;
};
typedef struct node node_t;

struct stats
{
 // node pointer pointing at the oldest and youngest person in the list
    struct node_t* oldest;
    struct node_t* youngest;

 // holding the number of birthdays in each month (0 = Jan. & 11 = Dec.)
    int numBD[12];
}; typedef struct stats list_stats_t;
list_stats_t getListStats(node_t *head)
{
    node_t* temp = head;

 // creates object to be returned and initializes it to the first node in a list
    list_stats_t stat;
    node_t* oldest = temp;
    node_t* youngest = temp;

    while (temp != NULL)  // loops through the list to find the oldest and youngest person
    {
     // if current node isn't the oldest, set the oldest to the next node   
        if (isOlder(oldest) == false)
            { oldest = temp->next; }
        if (isOlder(youngest) == false)
            { youngest = temp->next; }

        temp = temp->next;      // next value
    }

 // compiler warnings
    stat.oldest = oldest;
    stat.youngest = youngest;

    return stat;
}

我期望将 struct stats 中的 node_t 值分配给 getListStats() 中的 node_t 值。没有任何编译器错误,只有警告,但我也希望避免这些错误

c struct variable-assignment
1个回答
2
投票

您的节点类型有两个名称:

  • struct node
  • node_t

struct node_t
与这些不同,而不是您打算使用的类型。

© www.soinside.com 2019 - 2024. All rights reserved.