首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

改错,该如何解决

2012-02-12 
改错请帮我改错,谢谢!#includestdio.h#includemalloc.h#define null 0#define len sizeof(struct stud

改错
请帮我改错,谢谢!
#include<stdio.h>
#include<malloc.h>
#define null 0
#define len sizeof(struct student)
struct student
{
  long num;
  float score;
  struct student * next;
};
int n;
struct student *creat(void)
 {
   
  struct student *p1,*p2,*head;
  n=0;
  p1=p2=(struct student*) malloc(len);
  scanf("%ld,%f",&p1->num,&p2->score);
  head=null;
  while(p1->num!=0)
  {
  n=n+1;
  if(n==1) head=p1;
else p2->next=p1;
  p2=p1;
  p1=(struct student*)malloc(len);
  scanf("%ld,%f",&p1->num,&p1->score); 
  } 
p2->next=null;
return(head);
}
  void print (struct student *head)
{
struct student *p;
print("\nnow,there %d records are:\n",n);
p=head;
if(head!=null)
do
{
printf("%ld %5.ldf",p->num,p->score);
p=p->next;
}while (p!=null);
}
struct student *del(struct student *head,long num)
{
struct student *p1,*p2;
if(head==null) 
{
printf("\nlist null! \nlist null! \n");goto end;
}
p1=head;
while(num!==p1->num&&p1->next!==null\n")
{
p2=p1;p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)head=p1->next;
else p2->next=p1->next;
printf("delete:%ld\n",num);
n=n-1;
}
else printf("ld not been found! \n",num);
end;
return(head);
}
struct student * insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
{
p1=head;
p0=stud;
if(head==null)
{
head=p0;p0->next=null;
}
if(p0->num<=p1->num)&&(p1->next!=null))
{
p2=p1;
p1=p1->next;
}
if (p0->num<=p1->num)
{
if(head==p1) head=p0;
else p2->next=p0;
p0->next=p1;
else
{
p1->next=p0;p0->next=null;
}
n=n+1;
return(head);
main()
{
struct student * head,stu;
long del_num;
printf("input record :\n");
head=creat();
print(head);
printf("ninput the deleted number:");
scanf("%ld",&del_num);
head=del(head,del_num);
print(head);
printf("\ninput the inserted record:");
  scanf("%ld,%f",&stud.num,&stud.score);
head=insert(head,&stu);
print(head);
}

[解决办法]
就是一些小错误 自己在看下把

C/C++ code
#include  <stdio.h>  
#include <malloc.h>
#define  null  0
#define  len  sizeof(struct  student)
struct  student
{
  long  num;
  float  score;
  struct  student  *  next;
};
int  n;
struct  student  *creat(void)
{
   
struct  student  *p1,*p2,*head;
n=0;
  p1=p2=(struct  student*)  malloc(len);
    scanf("%ld,%f",&p1-> num,&p2-> score);
    head=null;
  while(p1-> num!=0)
  {
      n=n+1;
      if(n==1)  head=p1;
      else  p2-> next=p1;
      p2=p1;


    p1=(struct  student*)malloc(len);
      scanf("%ld,%f",&p1-> num,&p1-> score); 
    } 
    p2-> next=null;
return(head);
}
void  print(struct  student  *head)
{
    struct  student  *p;
printf("\nnow,there  %d  records  are:\n",n);
p=head;
if(head!=null)
do
{
  printf("%ld  %5.ldf",p-> num,p-> score);
  p=p-> next;
  }while  (p!=null);
}
struct  student  *del(struct  student  *head,long  num)
{
struct  student  *p1,*p2;
if(head==null)
{
printf("\nlist  null!  \nlist  null!  \n");
goto  end;
}
p1=head;
while(num!=p1->num&&p1->next!=null)
{
p2=p1;p1=p1-> next;
}
if(num==p1-> num)
{
if(p1==head)head=p1-> next;
else  p2-> next=p1-> next;
printf("delete:%ld\n",num);
n=n-1;
}
else  printf("ld  not  been  found!  \n",num);
end:
return(head);
}
struct  student  *  insert(struct  student  *head,struct  student  *stud)
{
struct  student  *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==null)
{
head=p0;p0-> next=null;
}
if((p0->num <p1-> num)&&(p1-> next!=null))
{
p2=p1;
p1=p1-> next;
}
if  (p0-> num <=p1-> num)
{
if(head==p1)  head=p0;
else  p2-> next=p0;
p0-> next=p1;
}
else
{
p1-> next=p0;p0-> next=null;
}
n=n+1;
return(head);
}
main()
{
struct  student  *head,stud;
long  del_num;
printf("input  record  :\n");
head=creat();
print(head);
printf("ninput  the  deleted  number:");
scanf("%ld",&del_num);
head=del(head,del_num);
print(head);
printf("\ninput  the  inserted  record:");
scanf("%ld,%f",&stud.num,&stud.score);
head=insert(head,&stud);
print(head);
}


[解决办法]
C/C++ code
#include <stdio.h> #include <malloc.h> #define   null   0 #define   len   sizeof(struct   student) struct   student {     long   num;     float   score;     struct   student   *   next; }; int   n; struct   student   *creat(void) {         struct   student   *p1,*p2,*head;     n=0;     p1=p2=(struct   student*)   malloc(len);     scanf("%ld,%f",&p1-> num,&p2-> score);     head=null;     while(p1-> num!=0)     {         n=n+1;         if(n==1)   head=p1;         else   p2-> next=p1;         p2=p1;         p1=(struct   student*)malloc(len);         scanf("%ld,%f",&p1-> num,&p1-> score);       }       p2-> next=null;     return(head); } void   print   (struct   student   *head) {     struct     student   *p;     printf("\nnow,there   %d   records   are:\n",n);     p=head;     if(head!=null)         do         {             printf("%ld   %5.ldf",p-> num,p-> score);             p=p-> next;         }while   (p!=null); } struct   student   *del(struct   student   *head,long   num) {     struct   student   *p1,*p2;     if(head==null)       {         printf("\nlist   null!   \nlist   null!   \n");goto   end;     }     p1=head;     while(num!=p1->num&&p1->next!=null)     {         p2=p1;p1=p1-> next;     }     if(num==p1-> num)     {         if(p1==head)head=p1-> next;         else   p2-> next=p1-> next;         printf("delete:%ld\n",num);         n=n-1;     }     else   printf("ld   not   been   found!   \n",num); end:     return(head); } struct   student   *   insert(struct   student   *head,struct   student   *stud) {     struct   student   *p0,*p1,*p2;     p1=head;     p0=stud;     if(head==null)     {         head=p0;p0-> next=null;     }     if((p0->num<=p1->num)&&(p1->next!=null))     {         p2=p1;         p1=p1-> next;     }     if   (p0-> num <=p1-> num)     {         if(head==p1)   head=p0;         else   p2->next=p0;         p0-> next=p1;     }    else     {         p1-> next=p0;p0-> next=null;     }     n=n+1;     return(head); }main() {     struct student *head,stu;     long   del_num;     printf("input   record   :\n");     head=creat();     print(head);     printf("ninput   the   deleted   number:");     scanf("%ld",&del_num);     head=del(head,del_num);     print(head);     printf("\ninput   the   inserted   record:");     scanf("%ld,%f",&stu.num,&stu.score);     head=insert(head,&stu);     print(head); } 


[解决办法]
#include <stdio.h> 
#include <malloc.h> 
#define null 0 
#define len sizeof(struct student) 
struct student 

long num;
float score;
struct student * next; 
}; 
int n; 
struct student *creat(void) 
{
struct student *p1,*p2,*head; 
n=0; 
p1=p2=(struct student*) malloc(len); 
scanf("%ld,%f",&p1-> num,&p2-> score); 
head=null; 
while(p1-> num!=0)

n=n+1; 
if(n==1)
head=p1; 
else
p2-> next=p1; 
p2=p1; 
p1=(struct student*)malloc(len); 
scanf("%ld,%f",&p1-> num,&p1-> score);
}
p2-> next=null; 
return(head);

void print (struct student *head)
{
struct student *p;
printf("\nnow,there %d records are:\n",n); 
p=head; 
if(head!=null) 
do 

printf("%ld %5.ldf",p-> num,p-> score);
p=p-> next; 
}while (p!=null); 

struct student *del(struct student *head,long num) 

struct student *p1,*p2;
if(head==null) 

printf("\nlist null! \nlist null! \n");
goto end;

p1=head;
while((num!=p1->num)&&(p1->next!=null))
{
p2=p1;
p1=p1-> next;

if(num==p1->num) 

if(p1==head)
head=p1->next; 
else
p2-> next=p1->next;
printf("delete:%ld\n",num);
n=n-1;
}
else
printf("ld not been found! \n",num);
end:
return(head);

struct student * insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
{
p1=head;
p0=stud;
if(head==null)

head=p0;p0-> next=null;

if((p0->num<=p1->num)&&(p1->next!=null)) 

p2=p1; 
p1=p1-> next; 

if (p0-> num <=p1-> num)

if(head==p1)
head=p0;
else
p2-> next=p0;
p0-> next=p1; 
}
else 

p1-> next=p0;
p0-> next=null;

n=n+1; 
return (head); 
void main() 

struct student *head,stud;
long del_num; 
printf("input record :\n"); 
head=creat(); 
print(head); 
printf("ninput the deleted number:"); 
scanf("%ld",&del_num); 
head=del(head,del_num); 
print(head); 
printf("\ninput the inserted record:"); 
scanf("%ld,%f",&stud.num,&stud.score);
head=insert(head,&stud);
print(head); 
}

热点排行
Bad Request.