日期:2014-05-16  浏览次数:20779 次

求各位大神的解答,linux一个小程序的问题,至今仍困扰着我!
其实这个程序就是想实现ls -al  的功能 ,但遇到一个问题,让我迟迟没有解决,上代码吧,大家复制代码后试试?
      1 #include<stdio.h>
      2 #include<stdlib.h>
      3 #include<unistd.h>
      4 #include<sys/types.h>
      5 #include<sys/stat.h>
      6 #include<dirent.h>
      7 #include<string.h>
      8 
      9 
     10 #define N_BITS 3
     11 #define MAX_PATH 80
     12 
     13 void output_dir_info(const char *new_docunment);
     14 void output_file_info(struct stat file);
     15 
     16 int main(int argc,char **argv)
     17 {
     18         char *docunment_path;
     19         docunment_path=(char *)malloc(sizeof(char)*MAX_PATH);
     20         getcwd(docunment_path,MAX_PATH);
     21         if(argc==1)                          //read current docunment   
     22                 output_dir_info(docunment_path);
     23         else if(argc==2)                     //panduan pramamter
     24         {
     25                 struct stat stat_file;
     26                 stat(argv[1],&stat_file);
     27                 if(S_ISREG(stat_file.st_mode))         //a file
     28                 {
     29                         output_file_info(stat_file);
     30                 }
     31                 else if(S_ISDIR(stat_file.st_mode))                             //a doc