Question

I get "passing argument 2 of ‘execvp’ from incompatible pointer type" and
expected ‘char * const*’ but argument is of type ‘const char **’
I'm wondering what the correct syntax is? Thanks!


int main(int argc, const char* argv[]) {
  if(argv[0]!=NULL)
    return -1;
  int pid = fork();
  if(pid==0)
    execvp(argv[0],argv+strlen(argv[0]));
  else
    wait();
  return 0;
}

Was it helpful?

Solution

exec functions don't accept const char*. In your case, simply change argv to char*, that's the correct prototype.

Btw. argv + strlen(argv[0]) doesn't make any sense, what did you mean by that?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top