开发者

execvpe argv to parameter matching syntax help needed

开发者 https://www.devze.com 2023-03-01 16:08 出处:网络
I get \"passing argument 2 of ‘execvp’ from incompatible pointer type\" and expected ‘char * const*’ but argument is of type ‘const char **’

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;
}


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消