C Warning passing argument 2 of ‘getopt’ from incompatible pointer type -


i write function getopt() options command line. when compile it, warning:

cc1: warnings being treated errors csim.c: in function ‘getarg’: csim.c:157: error: passing argument 2 of ‘getopt’ incompatible  pointer type /usr/include/getopt.h:152: note: expected ‘char * const*’  argument of type ‘const char **’ 

here c code:

#include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(){ }  int getarg(int argc, char const *argv[], int *verbose, int *ps,      int *pe, int *pb, char *tracefilename){     int arg;     int argcount;     while ((arg = getopt(argc, argv, "vs:e:b:t:")) != -1){         switch (arg){             case 'v':             *verbose = 1;             break;              default:             printf("%s\n", "illegal command arguments, please input again");             exit(-1);             break;         }     }      if(argcount < 4){         printf("%s\n", "illegal command arguments, please input again");             exit(-1);     }     return 0; } 

the problem is, error says, you're passing const char ** char * const* expected. you're passing argv (which has wrong type) getopt. fix changing type of argv.

int getarg(int argc, char * const argv[], int *verbose, int *ps, int *pe, int *pb, char *tracefilename) 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -