免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1169 | 回复: 3
打印 上一主题 下一主题

Segmentation fault!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-05 10:52 |只看该作者 |倒序浏览
  1. #include <sys/stat.h>;
  2. #include <stdio.h>;

  3. int isDir(const char *pathname) {

  4.     struct stat *statbuf;

  5.     if(stat(pathname, statbuf) == -1) {
  6.         return 0;
  7.     }

  8.     if(S_ISDIR(statbuf->;st_mode)) {
  9.         return 1;
  10.     }
  11.     else {
  12.         return 0;
  13.     }
  14. }

  15. int main(int argc, char *argv[]) {

  16.     if(isDir(argv[1])) {
  17.         printf("DIR\n");
  18.     }
  19.     else {
  20.         printf("NO DIR\n");
  21.     }
  22. }
复制代码


执行程序的时候,不管后面跟什么参数,都是段错误。请问哪里出错了,谢谢![/code]

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-06-05 11:06 |只看该作者

Segmentation fault!!

gdb.

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2005-06-05 11:07 |只看该作者

Segmentation fault!!

struct stat statbuf;

   if(stat(pathname, &statbuf) == -1)

论坛徽章:
0
4 [报告]
发表于 2005-06-05 11:38 |只看该作者

Segmentation fault!!

谢谢mq110
我正在学习LINUX编程。本来一直以为是pathname传送有错误,但用GDB看来看去没错误,原来是statbuf有错误。谢谢了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP