Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        4年前关闭。
                                                                                            
                
        
我正在尝试在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;
}

最佳答案

尝试将prinf更改为printf吗?

10-05 19:14