LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: mantou

About gcc in Mandrake 9.0!!!

[复制链接]
 楼主| 发表于 2002-11-2 13:11:47 | 显示全部楼层
AND in this pro.

#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 *head;
  struct student *p1,*p2;
  n=0;
  p1=p2=(struct student *)malloc(LEN);
  scanf("%ld,%f",&p1->num,&p1->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,These %d records are:\n",n);
p=head;
if(head != NULL)
   do
    {printf("%ld,%5.1f\n",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!\n");return(head);}
  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);
    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;}
    else
      {while((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 records:\n");
  head=creat();
  print(head);
  printf("\ninput the deleted number:");
  scanf("%ld",&del_num);
  while(del_num != 0)
      {head=del(head,del_num);
       print(head);
       printf("input the deleted number:");
       scanf("%ld",&del_num);}
  printf("\ninput the inserted record:");
  stu=(struct student *)malloc(LEN);
  scanf("%ld,%f",&stu->num,&stu->score);
  while(stu->num != 0)
      {head=insert(head,stu);
       print(head);
       printf("input the inserted record:");
       stu=(struct student *)malloc(LEN);
       scanf("%ld,%f",&stu->num,&stu->score);
      }
}






if there isn't some fit for  C ??


发表于 2002-11-2 13:12:09 | 显示全部楼层
这和 gcc 没有什么关系, 是标准 C 的问题.

> sort.c:3:1: warning: "NULL" redefined

这个很奇怪, 请把你的文件头五行贴一下.

#ifndef NULL
#define NULL 0
#endif  /* NULL */

这是预防对同一个宏 (NULL) 重复定义的做法. stdio.h 里面已经定义了 NULL, 所以要防止重新定义, 我的意见是这三行都应该删掉, NULL 现在已经是 standard library 里的定义了, 不用自己费事, 反而增加麻烦.

int main()

这是强化标准, 不使用默认返回类型的做法. 与此对应, 你的 main 函数里面最后一行要加上

return 0;

这是向系统报告程序成功返回.

当然这第二条是我个人意见, 你要实在不愿意加也可以, 不算违反标准.
发表于 2002-11-2 13:14:43 | 显示全部楼层
> AND in this pro.

> #define NULL 0
> #define LEN sizeof(struct student)
> struct student

这是文件的头吗? 应该还有

#include <stdio.h>

吧?
 楼主| 发表于 2002-11-2 13:15:11 | 显示全部楼层
[smallmantou@Smallmantou linuxC]$ gcc -o lianbiao lianbiao.c
lianbiao.c: In function `creat':
lianbiao.c:27: `next' undeclared (first use in this function)
lianbiao.c:27: (Each undeclared identifier is reported only once
lianbiao.c:27: for each function it appears in.)
lianbiao.c: In function `del':
lianbiao.c:49: parse error before '=' token
lianbiao.c: At top level:
lianbiao.c:51: parse error before "if"
lianbiao.c:54: parse error before string constant
lianbiao.c:54: warning: conflicting types for built-in function `printf'
lianbiao.c:54: warning: data definition has no type or storage class
lianbiao.c:55: initializer element is not constant
lianbiao.c:55: warning: data definition has no type or storage class
lianbiao.c:56: parse error before '}' token
lianbiao.c: In function `main':
lianbiao.c:98: incompatible types in assignment
lianbiao.c:99: invalid type argument of `->'
lianbiao.c:99: invalid type argument of `->'
lianbiao.c:100: invalid type argument of `->'
lianbiao.c:101: incompatible type for argument 2 of `insert'
lianbiao.c:104: incompatible types in assignment
lianbiao.c:105: invalid type argument of `->'
lianbiao.c:105: invalid type argument of `->'



it is the error!!!

oh my god!!!
  it is copied from the book!!!

高原之狼

  if you don't help me !!!  I will go die!!!!!

my god!!!!

i don't know where is the wrong ,and don't know the reason!!!
发表于 2002-11-2 13:25:41 | 显示全部楼层
仔细看看你有没有抄错什么, 尤其是第 27 行. 如果没有, 我很正式地建议你立刻把手里的书烧掉, 去找一本象样的教材.

我不是什么高手, 你的问题也不用高手, 任何认真的初学者都能找出问题所在. 你要是英语好, 自己看看 gcc 的信息也能明白.
 楼主| 发表于 2002-11-2 13:32:42 | 显示全部楼层
it's my jiaocai!
my english is poor,but i can't use chinese in linux!!


that you said the .H is the stdio.h??

the 27 line is the right!   in TC ,it can be passed!!

and i have make some pro. in the gcc 2.9 in REDHAT 7.2
and have no problem,

i think there is some update in the gcc 3.2,and C pro,must be 标准
发表于 2002-11-2 13:44:35 | 显示全部楼层
Line 27:  return(next);

这一句要是在任何一个 C 编译器下通过, 都会成为大笑话的.

我没有责备你英语差的意思, 是你要我用中文解释, 又不明白 gcc 的信息, 我才觉得你应该加强英语的.

什么是 standard C, 一时半会也说不清. 你要是认为你的教材对, 把那个程序在 Turbo C 或是 Red Hat + gcc 2.9.x 下编译通过的信息拿来给我看.
 楼主| 发表于 2002-11-2 13:45:06 | 显示全部楼层
    It has been auto-edited by fixincludes from:

        "/usr/include/stdio.h"

   / *        ISO C99 Standard: 7.19 Input/output        <stdio.h>
*/

#ifndef _STDIO_H

#if !defined __need_FILE && !defined __need___FILE
# define _STDIO_H        1
# include <features.h>

 楼主| 发表于 2002-11-2 14:01:20 | 显示全部楼层
this is about STDIO.H  in my linux !

thank you for your patient  to help me !!
it's in the  LIANBIAO  in my JIAOCAI ,

and i also think it's have problem  ,when i complie it in TC ,there is no error but ,the EXE run,it's not that we expected!!

now ,i want that there will more pepole to attention my problem,and can explain some,!

yell, i also want your help!!  goodman  高原之狼
 楼主| 发表于 2002-11-2 14:06:25 | 显示全部楼层
i am sorry that the 27 line is wrong ,and i have corrected,

it's  "  return(head) "
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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