当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

 ·求 database    »显示摘要«
    摘要: 求 database_access_enu.msm 文件一份,发到信箱及送100分,在线结帐! zzc205@wangyu.org 谢谢! ......
    摘要: 评定中级职称需要两篇论文, 我有论文但没有发表过, 这些论文拿出来不行吗? 有谁知道那里可以很快地发表出自己的论文? 谢谢! ......


一个关于链表的问题

代码如下:  
     
  #include   <alloc.h>  
  #include     "stdio.h"  
  struct   node   {long   num;  
            float   grade;  
            struct   node   *next;  
            };  
   
   
  struct   node   *creatlink()  
  {int   k;  
    long   nn;  
    struct   node   *head,*p,*q;  
    head=NULL;k=0;  
    printf("\nPlease   input   one   students   number   (0   is   over):");  
    scanf("%ld",&nn);  
    while   (nn!=0L)  
        {   k++;  
            p=(struct   node   *)malloc(sizeof(struct   node));  
            p->num=nn;  
            printf("\nPlease   input   grade:");  
            scanf("%f",&p->grade);  
            if(k==1)   head=p;  
            else             q->next=p;  
            q=p;  
            printf("\nPlease   input   next   students   number(0   is   over):");  
            scanf("%ld",&nn);  
        }  
    q->next=NULL;  
    return(head);  
  }  
   
  void   outputlink(head)  
  struct   node   *head;  
  {   struct   node   *p;  
      if   (head==NULL)  
          {printf("\n   NULL   LINK");  
            return;  
            }  
      printf("\n   NUMBER                         GRADE");  
      p=head;  
      while(p!=NULL)  
          {  
            printf("\n%8ld%10.1f",p->num,p->grade);  
            p=p->next;  
            }  
  }  
   
   
   
  main()  
  {struct   node   *head,*stu;  
    head=creatlink();  
    outputlink(head);  
    }  
   
  一个警告如下:Possible   use   of   q   before   definition   in   function   creatlink  
  无错误;  
  但运行后:输入任意一个整数后回车,按ALT+F5后出现:  
      please   input   grade:scanf:   floating   point   formats   not   linked  
      Abnormal   program   termination  
   
  各位大虾帮忙看看问题出在何处。俺在此跪谢;  
  注:俺是一只超菜鸟,希望仁兄们提拔  
 

NO.1   作者: laiben

几个小地方改正后如下  
  #include   <stdlib.h>  
  #include   <stdio.h>  
  struct   node   {long   num;  
  float   grade;  
  struct   node   *next;  
  };  
   
   
  struct   node   *creatlink()  
  {int   k;  
  long   nn;  
  struct   node   *head,*p,*q;  
  head=NULL;k=0;  
  printf("\nPlease   input   one   students   number   (0   is   over):");  
  scanf("%ld",&nn);  
  while   (nn!=0L)  
  {   k++;  
  p=(struct   node   *)malloc(sizeof(struct   node));  
  p->num=nn;  
  printf("\nPlease   input   grade:");  
  scanf("%f",&p->grade);  
  if(k==1)   head=p;  
  else   q->next=p;  
  q=p;  
  printf("\nPlease   input   next   students   number(0   is   over):");  
  scanf("%ld",&nn);  
  }  
  q->next=NULL;  
  return(head);  
  }  
   
  void   outputlink(struct   node   *head)  
  {   struct   node   *p;  
  if   (head==NULL)  
  {printf("\n   NULL   LINK");  
  return;  
  }  
  printf("\n   NUMBER   GRADE");  
  p=head;  
  while(p!=NULL)  
  {  
  printf("\n%8ld%10.1f",p->num,p->grade);  
  p=p->next;  
  }  
  }  
   
   
   
  void   main()  
  {struct   node   *head,*stu;  
  head=creatlink();  
  outputlink(head);  
  }  
   
  在vc6通过!  
 

NO.2   作者: liner44

whmily   (不回头的土豆)   。  
  这位仁兄是用Turbo   c   2.0调试的吧  
  Turbo   c   2.0有个bug  
  这是编译器的原因。  
  对结构体中的浮点数付值。会出错。  
  你的程序没有错。  
  你可以用Vc++测你的程序就行了。

NO.3   作者: chinazcw

什么都没改,Dev   C++通过~~~  
   
  不过看你的给出的警告,好像是说scanf()函数不支持对成员数据的直接赋值~~~

NO.4   作者: liner44

:Possible   use   of   q   before   definition   in   function   creatlink  
  while   (nn!=0L)  
  {    
      ......  
  }  
  q->next=NULL;  
   
  当nn一开始就等于0的时候。  
  q根本就不存在。也就是没有指向确切的地址。  
  q->next就不成立。  
 


    摘要: 我最近买了一本《用asp、visual basic、sql server7.0和mts》wrox出版社出的 到网站上没有找到原码,那位兄弟有给小生传一份。 谢谢,email:ta1@163.com ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE