红联Linux门户
Linux帮助

Linux 下的编程问题

发布时间:2011-03-05 21:09:20来源:红联作者:cshui202
各位高手 ,小弟初学linux,希望大家照顾。
用gcc调试一个简单c程序, 程序来源于 谭浩强的 《c语言程序设计》的简单链表一章。
代码如下:
1 #include
2 #define NULL 0
3 struct Brothers
4 { char name[20];
5 int height;
6 long money;
7 struct Brothers * next;
8 };
9
10 main()
11 {
12 struct Brothers boy[3] ;
13 struct Brothers * head;
14 struct Brothers * p;
15 head = boy;
16 strcpy(boy[1].name , "cshui");
17 boy[1].height = 169;
18 boy[1].money = 210165;
19 boy[1].next = &boy[2];
20 strcpy(boy[2].name , "yinghai");
21 boy[2].height = 170;
22 boy[2].money = 2;
23 boy[2].next = &boy[3];
24 strcpy(boy[3].name , "pengpeng");
25 boy[3].height = 165;
26 boy[3].money = 4353432;
27 boy[3].next = NULL;
28 p = head;
29 while(p != NULL)
30 {
31 printf("NAME : %S\nHEIGHT : %d\nMONEY : %ld\n\n", (*p). name ,(*p).height ,(*p).money );
32 p = (*P).next ;
33 }
34 }


用gcc -g 编译结果:
Simple_list.c:2: warning: "NULL" redefined
/usr/lib/gcc/i686-linux-gnu/4.4.5/include/stddef.h:400: note: this is the location of the previous definition
Simple_list.c: In function ‘main’:
Simple_list.c:31: warning: incompatible implicit declaration of built-in function ‘printf’
Simple_list.c:31: warning: format ‘%S’ expects type ‘wchar_t *’, but argument 2 has type ‘char *’
Simple_list.c:32: error: ‘P’ undeclared (first use in this function)
Simple_list.c:32: error: (Each undeclared identifier is reported only once
Simple_list.c:32: error: for each function it appears in.)


请问为什么 ,怎么修改,请详细点,谢谢!!
文章评论

共有 4 条评论

  1. Rockets 于 2011-03-09 14:55:46发表:

    还有个大小写的变量的问题哦 楼主 是小写的p不是大写的P

  2. pallana 于 2011-03-06 15:36:39发表:

    可能楼主使用Turbo C2.0学习的C语言。
    #include //在TC中可以不用,但是在其他编译器中可能需要使用
    int main()
    {
    return 0;
    }

    main函数需要有类型,然后需要返回0值。谭的书把这些省略了的。

  3. 我来迟了 于 2011-03-06 13:49:31发表:

    Simple_list.c:2: warning: "NULL" redefined
    NULL本身就是一宏,在这里你重复定义了
    Simple_list.c:31: warning: incompatible implicit declaration of built-in function ‘printf’
    没有声明printf,这个很明显是由于没有包含stdio库
    Simple_list.c:31: warning: format ‘%S’ expects type ‘wchar_t *’, but argument 2 has type ‘char *’
    格式输出的时候格式不正确

  4. 526rui399 于 2011-03-06 13:33:40发表:

    gcc貌似不能省略 主函数的函数类型