| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 931 人关注过本帖
标题: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
快速回复:C语言错误
数据加载中...
 
   



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

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