我在C中有下面的代碼。我在FreeBSD上運行它。我編譯它爲cc -o bbb bb.c
。然後運行並獲得輸出stat給沒有這樣的文件或目錄
$ ./bbb
-1
stat: No such file or directory
這是代碼:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
int main() {
struct stat *st;
int stat_code =0;
stat_code = stat("/", st);
printf("%d\n", stat_code);
perror("stat");
return 0;
}
考慮到你將未初始化的指針傳遞給stat,它對你來說太過分了,可能會更糟糕。 –
嗯,我通過「/」不知道如何可以未初始化? – Alexandr
@Alexandr:不*指針*。另一個。 –