-5
我想在linux中創建一個腳本,將所有文件大小從一個目錄彙總到一個變量中。到現在爲止我已成功地編寫代碼來打開和看到的是一個目錄裏面,雖然我收到以下錯誤,當我嘗試用gcc -o
命令編譯:如何添加文件大小
Error: [email protected]:~$ gcc -o dir Dir.c
/tmp/ccuNE2Q3.o: In function `main':
Dir.c:(.text+0xd8): undefined reference to `prinf'
collect2: error: ld returned 1 exit status
到目前爲止的代碼是:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
int main (int argc, char* argv[]){
struct stat buf;
struct dirent *entry;
DIR *dr;
if (argv[1]==NULL) {
printf("Utilizare: %s director\n", argv[0]);
exit(0);
}
stat (argv[1], &buf);
if (!S_ISDIR(buf.st_mode)) {
perror(argv[1]);
exit(0);
}
dr = opendir(argv[1]);
while(entry=readdir(dr)) {
prinf("%s\n", entry->d_name);
}
return 0;
}
考慮閱讀編譯器實際上對您所說的內容,因爲能夠閱讀和理解它非常重要,並且使查找解決方案變得更加容易。 –