鱼C论坛

 找回密码
 立即注册
查看: 3039|回复: 7

哪错了???

[复制链接]
发表于 2013-9-25 18:49:28 | 显示全部楼层 |阅读模式
2鱼币
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#define LEN sizeof(struct student)
struct student *creat();
void print (struct student *head);
struct student
{
int num;
float score;
struct student *next;
};
int n;
void main()
{
struct student *stu;
stu = creat();
print(stu);
printf("\n\n");
systen("pause");
}
struct student *creat()
{
struct student *head;
struct student *p1,*p2;
p1=p2=(struct student *)malloc(LEN);
printf("please enter the num:");
scanf("%d",&p1->num);
printf("please enter the score:");
scanf("%d",&p1->score);
head = NULL;
n=0;
while (p1->num)
{
  n++;
  if(1==n)
  {
   head = p1;
  }
  else
  {
   p2->next=p1;
  }
  p2=p1;
  p1=(struct student *)malloc(LEN);
  printf("please enter the num:");
  scanf("%d",&p1->num);
  printf("please enter the score:");
  scanf("%d",&p1->score);
}
p2->next=NULL;
return head;
}
void print(struct student *head)
{
struct student *p;
printf("\nthere are %d records!\n\n",n);
p=head;
if (head)
{
  do
  {
   printf("学号为%d的成绩是:%f\n",p->num,p->score);
   p=p->next;
  }while (p);
}
}


最佳答案

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2013-9-25 18:49:29 | 显示全部楼层
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#define LEN sizeof(struct student)
struct student *creat();
void print (struct student *head);
struct student
{
int num;
float score;
struct student *next;
};
int n;
void main()
{
struct student *stu;
stu = creat();
print(stu);
printf("\n\n");
system("pause");//兄台,你这写错了
}
struct student *creat()
{
struct student *head;
struct student *p1,*p2;
p1=p2=(struct student *)malloc(LEN);
printf("please enter the num:");
scanf("%d",&p1->num);
printf("please enter the score:");
scanf("%d",&p1->score);
head = NULL;
n=0;
while (p1->num)
{
  n++;
  if(1==n)
  {
   head = p1;
  }
  else 
  {
   p2->next=p1;
  }
  p2=p1;
  p1=(struct student *)malloc(LEN);
  printf("please enter the num:");
  scanf("%d",&p1->num);
  printf("please enter the score:");
  scanf("%d",&p1->score);
}
p2->next=NULL;
return head;
}
void print(struct student *head)
{
struct student *p;
printf("\nthere are %d records!\n\n",n);
p=head;
if (head)
{
  do 
  {
   printf("学号为%d的成绩是:%f\n",p->num,p->score);
   p=p->next;
  }while (p);
}
}
system写错了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-9-25 19:55:29 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-9-25 20:16:36 | 显示全部楼层
原来是有两个地方是%f,写成了%d了,终于没错了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-9-25 20:17:21 | 显示全部楼层
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#define LEN sizeof(struct student)
struct student *creat();
void print (struct student *head);
struct student
{
        int num;
        float score;
        struct student *next;
};
int n;
void main()
{
        struct student *stu;
        stu = creat();
        print(stu);
        printf("\n\n");
        system("pause");
}
struct student *creat()
{
        struct student *head;
        struct student *p1,*p2;
        p1=p2=(struct student *)malloc(LEN);
        printf("please enter the num:");
        scanf("%d",&p1->num);
        printf("please enter the score:");
        scanf("%f",&p1->score);
        head = NULL;
        n=0;
        while (p1->num)
        {
                n++;
                if(1==n)
                {
                        head = p1;
                }
                else
                {
                        p2->next=p1;
                }
                p2=p1;
                p1=(struct student *)malloc(LEN);
                printf("please enter the num:");
                scanf("%d",&p1->num);
                printf("please enter the score:");
                scanf("%f",&p1->score);
        }
        p2->next=NULL;
        return head;
}
void print(struct student *head)
{
        struct student *p;
        printf("\nthere are %d records!\n\n",n);
        p=head;
        if (head)
        {
                do
                {
                        printf("学号为%d的成绩是:%f\n",p->num,p->score);
                        p=p->next;
                }while (p);
        }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2013-9-25 20:43:51 | 显示全部楼层
system错可是比较低级的错误啊,
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-9-25 21:38:32 | 显示全部楼层
林黛玉的葬礼 发表于 2013-9-25 20:43
system错可是比较低级的错误啊,

我就一菜鸟,之前还不知道有system这东西。:dizzy:就当是学C的新手的反面教材吧:lol:
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2013-9-27 16:11:56 | 显示全部楼层
呵呵,新人求支持
呵呵,新人求支持
呵呵,新人求支持
呵呵,新人求支持:loveliness:
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-23 19:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表