| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 322 人关注过本帖
标题:错误不会改啊!链表的问题
只看楼主 加入收藏
兔彤
Rank: 1
来 自:北京
等 级:新手上路
帖 子:15
专家分:0
注 册:2012-11-20
结帖率:44.44%
收藏
已结贴  问题点数:10 回复次数:5 
错误不会改啊!链表的问题
#include<stdio.h>
#include<stdlib.h>
struct student
{
    char name[20];
    char idnum[8];
    char Clanum[4];
    float grade[10];
    struct student *addr;
};
int main()
{
    FILE *inFile;
    inFile=fopen("stuImformation.txt","a");
    int i;
    char ch;
   
    struct student *t1, *t2, *head;
    head = NULL;
   
    do
    {
        t2 = (struct student *)malloc(sizeof(struct student));
        
        printf("请输入学生的姓名:");
        scanf("%s", t2->name);
        printf("\n请输入学生的学号:");
        scanf("%s", t2->idnum);
        printf("\n请输入学生的班级:");
        scanf("%s", t2->Clanum);
        printf("\n请输入学生各科的成绩");
   
    for(i=1;i<11;i++)
    {
        scanf("%f",t2->grade[i]);
    }
        if(head == NULL)
        {
            head = t2;
            t1 = head;
        }

        else
        {
            t1->addr = t2;
            t1 = t1->addr;
        }
        getchar();
        printf("是否继续录入?(y or n)");
        ch = getchar();
    }while(ch!='y');
    fclose(inFile);

    return 0;
}
搜索更多相关主题的帖子: include 
2012-11-27 20:01
heroinearth
Rank: 10Rank: 10Rank: 10
来 自:云南曲靖
等 级:青峰侠
帖 子:430
专家分:1506
注 册:2011-10-24
收藏
得分:3 
    for(i=1;i<11;i++)
    {
        scanf("%f",t2->grade[i]);//grade数组只有10成员,下标应从0-9.

    }
        else
        {
            t1->addr = t2;
            t1 = t1->addr;//这里应把t2赋值给t1,使t1始终指向最后一个节点        }
2012-11-27 20:38
ltianc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:56
专家分:128
注 册:2012-10-16
收藏
得分:3 
#include<stdio.h>
#include<stdlib.h>
struct student
{
    char name[20];
    char idnum[8];
    char Clanum[4];
    float grade[10];
    struct student *addr;
};
int main()
{
    FILE *inFile;
    int i;
    char ch;
    struct student *t1, *t2, *head;
    inFile=fopen("stuImformation.txt","a");
    head = NULL;
   
    do
    {
        t2 = (struct student *)malloc(sizeof(struct student));
        
        printf("请输入学生的姓名:");
        scanf("%s", t2->name);
        printf("\n请输入学生的学号:");
        scanf("%s", t2->idnum);
        printf("\n请输入学生的班级:");
        scanf("%s", t2->Clanum);
        printf("\n请输入学生各科的成绩");
   
    for(i=1;i<11;i++)
    {
        scanf("%f",t2->grade[i]);
    }
        if(head == NULL)
        {
            head = t2;
            t1 = head;
        }

        else
        {
            t1->addr = t2;
            t1 = t1->addr;
        }
        getchar();
        printf("是否继续录入?(y or n)");
        ch = getchar();
    }while(ch!='y');
    fclose(inFile);

    return 0;
}


看这行吗,(我真怀疑这是不是你亲自编的)

世界等我去改变。
2012-11-27 20:43
ltianc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:56
专家分:128
注 册:2012-10-16
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
struct student
{
    char name[20];
    char idnum[8];
    char Clanum[4];
    float grade[10];
    struct student *addr;
};
int main()
{
    FILE *inFile;
    int i;
    char ch;
    struct student *t1, *t2, *head;
    inFile=fopen("stuImformation.txt","a");
    head = NULL;
   
    do
    {
        t2 = (struct student *)malloc(sizeof(struct student));
        
        printf("请输入学生的姓名:");
        scanf("%s", t2->name);
        printf("\n请输入学生的学号:");
        scanf("%s", t2->idnum);
        printf("\n请输入学生的班级:");
        scanf("%s", t2->Clanum);
        printf("\n请输入学生各科的成绩");
   
    for(i=1;i<11;i++)
    {
        scanf("%f",t2->grade[i]);
    }
        if(head == NULL)
        {
            head = t2;
            t1 = head;
        }

        else
        {
            t1->addr = t2;
            t1 = t1->addr;
        }
        getchar();
        printf("是否继续录入?(y or n)");
        ch = getchar();
    }while(ch!='y');
    fclose(inFile);

    return 0;
}


看这行吗,(我真怀疑这是不是你亲自编的)

世界等我去改变。
2012-11-27 20:44
wtw199186
Rank: 2
等 级:论坛游民
帖 子:55
专家分:78
注 册:2012-9-22
收藏
得分:3 
for(i=1;i<11;i++)
     {
        // scanf("%f",t2->grade[i]);
         scanf("%f",&(t2->grade[i]));
     }
2012-11-27 20:46
张朝成
Rank: 4
等 级:业余侠客
帖 子:149
专家分:265
注 册:2012-3-22
收藏
得分:3 
for(i=1;i<10;i++)
    {
        scanf("%f",t2->grade[i]);

    }
      
2012-11-27 21:14
快速回复:错误不会改啊!链表的问题
数据加载中...
 
   



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

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