Converting int to *char in C

I’m trying to convert int to *char array. But when I print atoi(p[0]) I always get 0. Why?

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main( int argc, char * argv[] ) {
  int sk;
  if(argc == 2) {
    char * p[1];
    sk = atoi(argv[1]);

    p[0]=(char *)&sk;
    printf("PID = %d PPID = %d SK = %d n", getpid(), getppid(), atoi(p[0]));

    if(atoi(p[0]) > 0) {
      execvp("./e", p);
    }
  }
  return 0;
}


Source: c#

Leave a Reply