John Boe
John Boe

Reputation: 3611

How declare function to pass one argument argv[i] at a time? In C

While debugging when I jump to function parseLayerFile filename is (char **) 0x40a04e <_Jv_RegisterClasses+4235342>... How to correct the declaration to get valid filename value?

void parseArgs(WRAPPER_t *w, int argc, char *argv[])
{
   int i;
   for (i=1 ;i<argc ;i++) {
        if (strcmp(argv[i],"-layers") == 0) {
          i++;
          parseLayerFile(argv[i]);
        }
    } // for
}

int parseLayerFile(WRAPPER_t * w, char*filename[]){
  unsigned char * buffer; size_t size;
  size = get_fileContent(filename, &buffer);
}

int main(int argc, char **argv)
{
      WRAPPER_t * w;
      w = create_wrapper(); // w - main object
      threads_init(w);
      parseArgs(w, argc, argv);
      return 0;
}

Upvotes: 0

Views: 112

Answers (1)

alk
alk

Reputation: 70941

int parseLayerFile(WRAPPER_t * w, char*filename[])

expects two parameters.

You are calling it with only one parameter:

parseLayerFile(argv[i]);

As none of the argument suit your needs, fix the function as follows:

int parseLayerFile(const char * filename)
{
  unsigned char * buffer; 
  size_t size = get_fileContent(filename, &buffer);
}

Upvotes: 1

Related Questions