歡迎您光臨本站 註冊首頁

Linux 下的編程問題

←手機掃碼閱讀     火星人 @ 2014-03-22 , reply:0

各位高手 ,小弟初學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.)


請問為什麼 ,怎麼修改,請詳細點,謝謝!!

[火星人 ] Linux 下的編程問題已經有436次圍觀

http://coctec.com/docs/linux/show-post-102488.html