-1
      int main(int argc, char *argv[]) {
    int opt= 0;
    int start = -1, end = -1;
    char *alg,*dir,*graph;
   //Specifying the expected options
   //The two options s and e expect numbers as argument
    static struct option long_options[] = {
    {"start",no_argument,0,'s' },
    {"end",no_argument,0,'e' },
    {"algorithm",no_argument, 0,'a' },
    {"directory",required_argument, 0,'d' },
    {"graph",required_argument,0,'g' },
    {0,0,0,0}
   };

    int long_index =0;
    int i=0,j=0;
    size_t size = 1;
    while ((opt = getopt_long(argc, argv,"s:e:a:d:h:g:",
           long_options, &long_index )) != -1) {
         switch (opt) {
         case 'd' :
                dir = optarg;

                  if (optarg == NULL)
                     printf("d option is must");
                  else if
                     {
                     // How to verify the path provided is Correct/existing
                     }
                   else 
                       {
                        // Any more options of error handling on path 
                         provided is available ? 
                        }

The user passes directory path with option -d , How to verify the path is correct or not ?

What else error checking can be included for this ?

programmer
  • 71
  • 1
  • 12

1 Answers1

0

If you are trying to open a file in that directory open it and check if it opened

FILE *infile=fopen("<directory>/<filename>","r");
if(infile==NULL){
    printf("File did not open\n");  //implies directory or filename is invalid
}

Though I am not sure this is what you are asking. Please specify more

Parth K
  • 587
  • 5
  • 18