Chinaunix
标题:
在linux下运行出错
[打印本页]
作者:
冰轮月弧
时间:
2016-07-13 12:32
标题:
在linux下运行出错
#include <stdio.h>
main()
{
system("echo 'begin:'");
int a,b,c,a1,b1,c1,i,flag;
FILE *out = fopen("~/c++/in","r+");
flag=0;
for (i=100;i<1000;i++)
{
a=i%10; //this is geweishu
b=(i/10)%10; //this is shiweishu
c=i/100; //this is baiweishu
a1=a*a*a; //geweishu*3
b1=b*b*b; //shiweishu*3
c1=c*c*c; //baiweishu*3
if(a1+b1+c1)
{
flag++;
fprintf(out,"%d",i);
}
}
fclose(out);
printf("%d",flag);
}
这是自己做的水仙花数的练习,打算把C和SHELL结合在一起,但是在执行a.out文件的时候出现以下错误
[root@A12 c++]# ./a.out
begin:
段错误 (core dumped)
求解决方式
作者:
bskay
时间:
2016-07-13 12:56
FILE *out = fopen("~/c++/in","r+");
这个要检查返回值
~ 是shell扩展的,c不会帮你扩展的
作者:
冰轮月弧
时间:
2016-07-13 14:07
回复
2#
bskay
该怎么做呢。。
作者:
冰轮月弧
时间:
2016-07-13 14:13
回复
2#
bskay
检查了下 把~/C++/in改成/root/c++/in就可以了 谢谢
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2