QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

楼主: nextw3

为什么gcc编译c程序函数不能用void哪?

[复制链接]
 楼主| 发表于 2004-6-10 19:24:42 | 显示全部楼层
对,是弄错了指针和地址的级别t=&x,left和right我感觉分配内存了,malloc里有啊
回复

使用道具 举报

发表于 2004-6-10 19:52:24 | 显示全部楼层
用void声明函数确实在编译时产生警告,但这不一定是错误,只要你确信自己不用返回值,可以不必理会它,或者在编译时不要产生警告信息。
回复

使用道具 举报

发表于 2004-6-10 19:55:06 | 显示全部楼层
[code:1]
test13.c:12: warning: implicit declaration of function `printf'
test13.c:13: warning: implicit declaration of function `scanf'
test13.c:13: warning: format argument is not a pointer (arg 2)
test13.c:15: warning: implicit declaration of function `malloc'
test13.c:20: warning: assignment from incompatible pointer type
test13.c:21: warning: int format, pint arg (arg 2)
test13.c:21: warning: int format, pointer arg (arg 4)
test13.c:21: warning: unsigned int format, pointer arg (arg 5)
test13.c:21: warning: too few arguments for format
test13.c: In function `vis_a':
test13.c:28: warning: suggest parentheses around assignment used as truth value
test13.c:29: warning: unsigned int format, pint arg (arg 2)
test13.c:29: warning: unsigned int format, pointer arg (arg 4)
test13.c:29: warning: unsigned int format, pointer arg (arg 5)[/code:1]
你把些改改吧。改过后可以运行。
回复

使用道具 举报

发表于 2004-6-10 20:43:11 | 显示全部楼层
[quote:8013a2bb0c="nextw3"]对,是弄错了指针和地址的级别t=&x,left和right我感觉分配内存了,malloc里有啊[/quote]
噢,又看错了,是已经分配
回复

使用道具 举报

 楼主| 发表于 2004-6-10 21:00:15 | 显示全部楼层
好的,多谢帮忙.看着这么多的警告好头大啊
回复

使用道具 举报

发表于 2004-6-10 21:04:37 | 显示全部楼层
实际上都是你不太细心啊
回复

使用道具 举报

 楼主| 发表于 2004-6-10 21:12:46 | 显示全部楼层
版主说的没错,看了看都是低级错误
例如scanf("%d",dat);   dat前没加&
还有printf("     The %d dian address is:  %o  ,the data is %d ,the lchild is  %o  ,the  rchild is  %o\n",x,x->data,x->left,x->right);
5个%后面写了4个变量~~~~~~~~
我哭 看来以后还要多锻炼~~
回复

使用道具 举报

 楼主| 发表于 2004-6-11 08:52:19 | 显示全部楼层
t=&x好像不行,必须*t=x才可以
回复

使用道具 举报

发表于 2004-6-11 09:07:54 | 显示全部楼层
你是不是要这个结果:[code:1]
please you put the data:1 2 3 4 5
The 9385817 dian address is: 1171110010 ,the data is 1 ,the lchild is 0 ,the rchild is 0please you put the data: The 9385818 dian address is: 1171110030 ,the data is 2 ,the lchild is 0 ,the rchild is 0please you put the data: The 9385819 dian address is: 1171110050 ,the data is 3 ,the lchild is 0 ,the rchild is 0please you put the data: The 9385820 dian address is: 1171110070 ,the data is 4 ,the lchild is 0 ,the rchild is 0please you put the data: The 9385821 dian address is: 1171110110 ,the data is 5 ,the lchild is 0 ,the rchild is 0[/code:1]
回复

使用道具 举报

 楼主| 发表于 2004-6-11 09:21:16 | 显示全部楼层
是啊  不过还是有错误啊
我输入1 2 3  0 4 0 0 5 0 0 6 0 7 8 0 0 9 0 0
后 前三个可以正确输出,后面又是段错误~  我看看吧
由于是用的递归,最后好像要1 2 3 4 5 0 0 0 0 0 0才好
[code:1]
please you put the data:1 2 3 4 5 0 0 0 0 0 0
     The 1898329 dian address is:  1132560010  ,the data is 1 ,the lchild is  0  ,the  rchild is  0
please you put the data:     The 1898330 dian address is:  1132560030  ,the data is 2 ,the lchild is  0  ,the  rchild is  0
please you put the data:     The 1898331 dian address is:  1132560050  ,the data is 3 ,the lchild is  0  ,the  rchild is  0
please you put the data:     The 1898332 dian address is:  1132560070  ,the data is 4 ,the lchild is  0  ,the  rchild is  0
please you put the data:     The 1898333 dian address is:  1132560110  ,the data is 5 ,the lchild is  0  ,the  rchild is  0
[/code:1]
最后出现的是段错误
我输入是这么个结果  是否应该输入一个按一下回车那?

哦  再
void vis_a(pint t)
{
  if (!t) return;
  if (t->data==0) return;
  printf("the jiedian adress is %o,data is %d, lchild is %o,rchild is %o\n ",t,t->data,t->left,t->right);
  vis_a(t->left);
  vis_a(t->right);
  return;
}
加了一个if (!t) return; 可以正常显示了,不过最后还是显示了一个段错误
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-8 05:42 , Processed in 0.048130 second(s), 13 queries .

© 2021 Powered by Discuz! X3.5.

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