Chinaunix

标题: Segmentation fault!! [打印本页]

作者: rainysky    时间: 2005-06-05 10:52
标题: Segmentation fault!!
  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]
作者: mq110    时间: 2005-06-05 11:06
标题: Segmentation fault!!
gdb.
作者: mq110    时间: 2005-06-05 11:07
标题: Segmentation fault!!
struct stat statbuf;

   if(stat(pathname, &statbuf) == -1)
作者: rainysky    时间: 2005-06-05 11:38
标题: Segmentation fault!!
谢谢mq110
我正在学习LINUX编程。本来一直以为是pathname传送有错误,但用GDB看来看去没错误,原来是statbuf有错误。谢谢了




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2