linux c fgets 函数 出现段错误 请大神指正
intifmount(char**spath,char**dpath){FILE*fp;charbuf[BUF];char*sou,*des;intsp=0,dp=0;i...
int ifmount(char **spath,char **dpath)
{
FILE* fp;
char buf[BUF];
char *sou, *des;
int sp=0,dp=0;
if(fp = fopen("/proc/mounts","r") == NULL)
{perror("File open error\n");}
else
{
printf("aaaaaaaaaaaaaaa\n");
while((fgets(buf,BUF,fp)) != NULL)
{
printf("aaaaaaaaaaaaaaa\n");
sou=strtok(buf," ");
des=strtok(NULL," ");
sp=strcmp(*spath,sou);
dp=strcmp(*dpath,des);
if(sp == 0 && dp == 0)
{
fclose(fp);
return 1;
}
}
}
fclose(fp);
return -1;
}
BUF 是宏定义 值为1024 第一个aaaaaaaaaaaaaaa 可以打印出来第二个aaaaaaaaaaaaaa打印不出来程序段错误请大神指正。 展开
{
FILE* fp;
char buf[BUF];
char *sou, *des;
int sp=0,dp=0;
if(fp = fopen("/proc/mounts","r") == NULL)
{perror("File open error\n");}
else
{
printf("aaaaaaaaaaaaaaa\n");
while((fgets(buf,BUF,fp)) != NULL)
{
printf("aaaaaaaaaaaaaaa\n");
sou=strtok(buf," ");
des=strtok(NULL," ");
sp=strcmp(*spath,sou);
dp=strcmp(*dpath,des);
if(sp == 0 && dp == 0)
{
fclose(fp);
return 1;
}
}
}
fclose(fp);
return -1;
}
BUF 是宏定义 值为1024 第一个aaaaaaaaaaaaaaa 可以打印出来第二个aaaaaaaaaaaaaa打印不出来程序段错误请大神指正。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询