mercredi 27 décembre 2017

Random char* args[] to pass to execv

I need to create a char* array[] that i then have to pass to execv.

  • the first element would be the path "./exec_test"
  • for the second argument: pick randomly between A/B
  • for the third argument: pick a random letter A - Z
  • for the fourth argument: pick random integer between [2, 2+A_CONST]
  • Then NULL

    void perform_exec(){
        char *type= 'A' + (random() % 2);
        char *name= 'A' + (random() % 64);
        int rand_num= rand(); 
    
        char *args[5];
        args[0]= "./test_exec";
        args[1]= name;
        args[2]= type;
        args[3]= rand_num;
        args[4]= NULL;
    
        execv(args[0], args);
        printf("you souldn't see this. exec error\n");
        exit(EXIT_FAILURE);
    
    

    }

I know there is something terribly wrong with this code, but can't actually figure out what it is.

i get Error #014: Bad address.




Aucun commentaire:

Enregistrer un commentaire