Chinaunix
标题:
Segmentation fault!!
[打印本页]
作者:
rainysky
时间:
2005-06-05 10:52
标题:
Segmentation fault!!
#include <sys/stat.h>;
#include <stdio.h>;
int isDir(const char *pathname) {
struct stat *statbuf;
if(stat(pathname, statbuf) == -1) {
return 0;
}
if(S_ISDIR(statbuf->;st_mode)) {
return 1;
}
else {
return 0;
}
}
int main(int argc, char *argv[]) {
if(isDir(argv[1])) {
printf("DIR\n");
}
else {
printf("NO DIR\n");
}
}
复制代码
执行程序的时候,不管后面跟什么参数,都是段错误。请问哪里出错了,谢谢![/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