#include #include #include #include int main(int argc, char **argv) { char* ivalue = "index"; // Set default linked list filename char* nvalue = "filenames"; // Set default file array filename //char* currentFile = NULL; // Current file we're processing int index; // Index of last element in cmd line options int numFiles = 0; // Number of files to index int cmdo; // Command line option FILE* fp; // File pointer, used by all the files we open while ((cmdo = getopt (argc, argv, "hi:n:")) != -1) { switch(cmdo) { case 'i': // Specify what linked list file we're using ivalue = optarg; break; case 'n': // Specify what file array filename to use nvalue = optarg; break; case 'h': // Help, usage printf("indexfile [-i FILE] [-n FILE] FILE ...\nOPTIONS\n\t-i FILE\n\t\tWrite the linked list to FILE. This overrides the default file name \"index\".\n\t-n FILE\n\t\tWrite the array of file names to FILE. This overrides the default file name \"filenames\".\n"); return(0); case '?': fprintf(stderr, "Unrecognised option: -%c\n", optopt); return(1); break; default: break; } } numFiles = argc-optind; printf("%d\n",argc-optind); // !!!! ----------- THIS LINE --------- !!!!!!!! char** files[argc-optind]; // Create a character array of arrays for each filename specified for (index = optind; index < argc; index++) { *files[index-optind]= argv[index]; fp = fopen(*files[index-optind],"r"); if (fp) { printf("Successfully opened input file %s\n",*files[index-optind]); fclose(fp); } else { fprintf(stderr,"Can't open input file %s\n",*files[index-optind]); } } return(0); }