在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文件的时候出现以下错误
# ./a.out
begin:
段错误 (core dumped)
求解决方式 FILE *out = fopen("~/c++/in","r+");
这个要检查返回值
~ 是shell扩展的,c不会帮你扩展的 回复 2# bskay
该怎么做呢。。 回复 2# bskay
检查了下 把~/C++/in改成/root/c++/in就可以了 谢谢
页:
[1]