3

I'm trying to pass an archive and directory name command line arguments and extract a list of files in the directory. In eclipse I'm using "-A [archive.a] [directory_name]", but eclipse keeps trying to compile the test directory files. Any suggestions? Code sample below is a condensed version of my program: [Edit: ok, I got it to compile by moving out of the working directory...buts it's crashing at the readdir command...any tips?] [Edit: ok just found out I can manually parse the files so I guess this question is academic now. Thx all.]

int main(int argc, char **argv)                 
{      
    char **fileList = (char **)(malloc(sizeof(char *) * argc));
    output = argv[2];        //archive name
    DIR *d;
    struct dirent *dir;
    d = opendir(argv[3]);        //directory name

    int i = 0;
    while((dir = readdir(d) != NULL))
    {
        fileList[i] = (char *)(malloc(sizeof(char) * strlen(dir->d_name)));
        fileList[i] = dir->d_name;        //extract file names into array of strings
        ++i;
    }
    int j;
    for(j = 0; j <= argc; ++j)
    printf("%s\n", fileList[j]);        //print out list of file names

    closedir(d);
}
4

0 回答 0