| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 650 人关注过本帖
标题:为什么最后运行时有错误啊????请指教
只看楼主 加入收藏
mengcan555
Rank: 4
等 级:业余侠客
帖 子:104
专家分:253
注 册:2011-9-17
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
为什么最后运行时有错误啊????请指教
#include<stdio.h>

#include<stdlib.h>
typedef struct LNode
{
int number;
char name[10];
double mathstore;
struct LNode *next;
}LNode,*Linklist;


Linklist createlist(int n);
int main()
{   int n;  
printf("请输入需要输入的学生人数:\n");
     scanf("%d",&n);
createlist(n);
return 0;

}

Linklist createlist(int n)
{
    Linklist L,cur;
LNode *p;
char temp,ch;int j=0;
L=(Linklist)malloc(sizeof(LNode));
cur=(Linklist)malloc(sizeof(LNode));
L->next=NULL;   //建一个空表。
for(int i=n;i>0;i--)
{
p=(Linklist)malloc(sizeof(LNode));//生成新节点。
printf("请输入学生的学号:\n");
     scanf("%d",&p->number);
     printf("请输入该生的姓名:\n");
     temp=getchar();
     ch=getchar();
        while(ch!='\n')
     {
   
         scanf("%c",&p->name[j]);
            j++;
         ch=getchar();
     }
        p->name[j]='\0';
     printf("请输入该生的数学成绩:\n");
     scanf("%lf",&p->mathstore);
           L->next=p;
           p->next=cur;
           cur=p;
           
           
}



return L;

}              
搜索更多相关主题的帖子: include double number return 
2011-10-03 16:15
larryliu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:58
专家分:128
注 册:2011-9-30
收藏
得分:7 
temp=getchar();              /*这里吸取了个换行符*/
          ch=getchar();              /*那这里是什么意思?*/
        while(ch!='\n')
         {
             scanf("%c",&p->name[j]);      /*名字用字符串的gets();吧这样不好*/
             j++;
             ch=getchar();
         }
        p->name[j]='\0';
我是初学的,对这些也不是很清楚,有什么问题见谅啊~~
2011-10-03 17:01
mengcan555
Rank: 4
等 级:业余侠客
帖 子:104
专家分:253
注 册:2011-9-17
收藏
得分:0 
ch=getchar();              /*那这里是什么意思?*/
这是输入字符啊,要不#include<stdio.h>

#include<stdlib.h>
typedef struct LNode
{
    int number;
    char name[10];
    double mathstore;
    struct LNode *next;
}LNode,*Linklist;


Linklist createlist(int n);
void print_list(Linklist l);
int main()
{
    int n;  
    printf("请输入需要输入的学生人数:\n");
    scanf("%d",&n);
   
    print_list(createlist(n));
    return 0;
}

Linklist createlist(int n)
{
    Linklist L,cur;
    LNode *p;
    char temp,ch;
    int j=0;
    L=(Linklist)malloc(sizeof(LNode));
    cur=(Linklist)malloc(sizeof(LNode));
    L->next=NULL;   //建一个空表。

    cur=L; //cur初始化指向最后一个元素,尾插法

    for(int i=n;i>0;i--)
    {
        p=(Linklist)malloc(sizeof(LNode));//生成新节点。
        
        printf("请输入学生的学号:\n");
        scanf("%d",&p->number);        

        printf("请输入该生的姓名:\n");
        //temp=getchar();
        getchar();//接收上一次输入的回车符号
        ch=getchar();

        j=0; // j循环初始化
        while(ch!='\n')
        {
            //scanf("%c",&p->name[j]);
            p->name[j]=ch;
            j++;
            ch=getchar();
        }
        p->name[j]='\0';

        printf("请输入该生的数学成绩:\n");
        scanf("%lf",&p->mathstore);

        p->next=NULL;

        cur->next = p;        

        //L->next=p;
        //p->next=cur;
        cur=p;
    }
    return L;
}                  

void print_list(Linklist l)
{
    l=l->next;
    while(l)
    {
        printf("name:%s,number:%d,mathstore:%2.2lf\n",l->name,l->number,l->mathstore);
        l=l->next;
    }
   
}
然怎么判断循环条件啊,呵呵,我已经搞好了
2011-10-03 18:49
快速回复:为什么最后运行时有错误啊????请指教
数据加载中...
 
   



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

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