| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 480 人关注过本帖
标题:出现了一个不明白的问题请教一下(TAG)
只看楼主 加入收藏
zhuwei168
Rank: 1
来 自:东软信息学院
等 级:新手上路
帖 子:180
专家分:0
注 册:2008-2-13
收藏
 问题点数:0 回复次数:0 
出现了一个不明白的问题请教一下(TAG)
#include<stdio.h>
#include<stdlib.h>
typedef struct student
{
    int num;
    char name[10],sex[10];
    float score;
    struct student *next;
}STU;
STU *insert(STU *head);
main()
{
    STU *head=NULL;
    insert(head);


}
STU *insert(STU *head)
{
    STU *q,*temp;
    int temp1;
    float temp2;
    head=(STU *)malloc(sizeof(STU));
    head->next=NULL;

    q=head;
    while(1)
    {
        printf("请输入学号(以-1结束):\n");
        scanf("%d",&temp1);
        if(temp1==-1)
            break;
        temp=(STU*)malloc(sizeof(STU));
        temp->next=NULL;
        temp->num=temp1;
        printf("请输入姓名:\n");
        scanf("%s",temp->name);
        printf("请输入性别:\n");
        scanf("%s",temp->sex);
        printf("请输入学生成绩:\n");
        scanf("%f",&temp2);
        temp->score=temp2;
        q->next=temp;
        temp=temp->next;
    }
    return head;
}
#include<stdio.h>
#include<stdlib.h>
typedef struct student
{
    int num;
    char name[10],sex[10];
    float score;
    struct student *next;
}STU;
STU *insert(STU *head);
main()
{
    STU *head=NULL;
    insert(head);


}
STU *insert(STU *head)
{
    STU *q,*temp;
    int temp1;
    head=(STU *)malloc(sizeof(STU));
    head->next=NULL;

    q=head;
    while(1)
    {
        printf("请输入学号(以-1结束):\n");
        scanf("%d",&temp1);
        if(temp1==-1)
            break;
        temp=(STU*)malloc(sizeof(STU));
        temp->next=NULL;
        temp->num=temp1;
        printf("请输入姓名:\n");
        scanf("%s",temp->name);
        printf("请输入性别:\n");
        scanf("%s",temp->sex);
        printf("请输入学生成绩:\n");
        scanf("%f",&temp);
        q->next=temp;
        temp=temp->next;
    }
    return head;
}
为什么上面的第二种在独立的时候就不能正常运行需要第一种才可以,
但是在创建链表的时候,第二种却是可以的,为什么???
谢谢

[[it] 本帖最后由 zhuwei168 于 2008-6-3 10:36 编辑 [/it]]
搜索更多相关主题的帖子: 新的出的问题 
2008-06-03 10:29
快速回复:出现了一个不明白的问题请教一下(TAG)
数据加载中...
 
   



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

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