【发布时间】:2015-12-18 08:20:58
【问题描述】:
我正在尝试在 linux 中创建一个脚本,它将目录中的所有文件大小汇总到一个变量中。到目前为止,我已经设法编写代码来打开并查看目录中的内容,尽管当我尝试使用 gcc -o 命令编译它时出现以下错误:
Error: admin1@admin1-virtual-machine:~$ 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;
}
【问题讨论】:
-
考虑阅读编译器实际告诉您的内容,因为能够阅读和理解它非常重要,并且可以更轻松地找到解决方案。