LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1200|回复: 10

高手帮忙看一下这个程序有什么地方不错了!!!!!!

[复制链接]
发表于 2003-7-6 13:23:49 | 显示全部楼层 |阅读模式
我的系统的RH9,刚才照书上写了一个使用函数返回值的程序,自已看了很久,好像没有一个地方是错的,可就是编译不了。

程序如下:

#include <stdio.h>
double power(double n,int p);
int main(void)
{
double x,xpow;
int exp;

while (scanf("%lf%d",&x,&exp)==2)
{
  xpow=power(x,exp);
  printf("%g %d %g",x,exp,xpow);
}
return 0
}

double power(double n,int p)
{
double pow=1;
int i;
for(i=1;i<=p;i++)
   pow*=n;
return pow;
}
 楼主| 发表于 2003-7-6 13:29:11 | 显示全部楼层
运行gcc后提示如下:
[root@localhost cai]# gcc a.c
a.c: In function `main':
a.c:14: parse error before '}' token
a.c:20: `p' undeclared (first use in this function)
a.c:20: (Each undeclared identifier is reported only once
a.c:20: for each function it appears in.)
a.c:21: `pow' undeclared (first use in this function)
a.c:21: `n' undeclared (first use in this function)
a.c:23:2: warning: no newline at end of file
发表于 2003-7-6 13:33:21 | 显示全部楼层
main()函数中的return 0后面少了个分号,害得我找了半天。。。
 楼主| 发表于 2003-7-6 13:38:15 | 显示全部楼层
加上了,可还是不行,gcc后提示如下:

[root@localhost cai]# gcc a.c
a.c:23:2: warning: no newline at end of file
发表于 2003-7-6 13:49:54 | 显示全部楼层
你用的一定是 gedit
在文件尾加上一个空行就行了。
 楼主| 发表于 2003-7-6 13:55:00 | 显示全部楼层
可以说明白点吗!什么是"文件尾"?????????
因为在Linux下运行C我是第一回,以前都是在Windows下的,
发表于 2003-7-6 13:59:09 | 显示全部楼层
可以编译和运行,至于提示:
无关要精的,说你最后一行没结束的意思
你在最后一行那个大括号加上回车就不会有了。

 楼主| 发表于 2003-7-6 14:34:07 | 显示全部楼层
行了,但是为什么呢,可否说明一下。
 楼主| 发表于 2003-7-6 22:26:56 | 显示全部楼层
可以说一下为什么要在最后一行加上回车吗???
发表于 2003-7-7 00:35:25 | 显示全部楼层
不晓得,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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