标题:C语言错误
只看楼主
qq4056
Rank: 1
等 级:新手上路
帖 子:22
专家分:3
注 册:2014-11-18
 问题点数:0 回复次数:1 
C语言错误
程序代码:
#include <stdio.h>

typedef struct student
{
    char name[12];
    int id;

}student;

typedef struct node
{
    student data;
    struct node *next;
}*node;

node *create_link()
{
    node *head;

    head = (node *)malloc(sizeof(node));

    if(head == NULL)
    {
        printf("申请空间失败");
        exit(0);
    }
    printf("................\n");
    // error: request for member 'data' in something not a structure or union
    head->next = NULL;
   
    // error: request for member 'data' in something not a structure or union
    head ->data->name[0] = '\0';


    return head;
}

void add_link(node *head)
{

}

void print_link(node *head)
{
    node *temp = head;

    while(temp != NULL)
    {
        printf("%s ", temp->data.name);// error: request for member 'data' in something not a structure or union
        printf("%s ", temp->data.name);// error: request for member 'data' in something not a structure or union
                          
        printf("%d ", temp->data.id);// error: request for member 'data' in something not a structure or union
        temp = temp ->next;
    }
    putchar(10);
}

int main(void)
{
    node *head=create_link();


    print_link(head);




    printf("Hello World!\n");
    return 0;
}


搜索更多相关主题的帖子: C语言 
2015-06-10 22:44
qq4056
Rank: 1
等 级:新手上路
帖 子:22
专家分:3
注 册:2014-11-18
得分:0 
问题已经解决。。。。应该是:
typedef struct node
{
    student data;
    struct node *next;
}node;
2015-06-10 23:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-446457-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.594267 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved