I have to create multiple process using execve in C and passing it a binary file | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I have to create multiple process using execve in C and passing it a binary file

hi, the problem is that the compiler doesn't accept the main in the binary file: #include <stdio.h> #include <time.h> #include <stdlib.h> #include <stdio.h> extern char **environ; void Giocatore( char n_pedine, char base, char altezza, char *A ){ int x=n_pedine; while(x>0){ A[rand()%(altezza*altezza)]='O'; x--; } wait(NULL); } int main( int w, char *Arg[]){ Giocatore(*Arg[0], *Arg[1], *Arg[2], Arg[3]); } FILE C #include <time.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include "Giocatore.c" #define "Giocatore" char SO_NUM_G=2; char SO_NUM_P=10; char SO_BASE=60; char SO_ALTEZZA=20; char * posizione(char base, char altezza, char *A){ int i=0; for(i=0; i<altezza*base; i++){ if(A[i]=='O'){ return &A[i]; } } } void master(){ char A[SO_ALTEZZA][SO_BASE]; int i=0; for(i=0; i<SO_ALTEZZA; i++){ int j=0; for(j=0; j<SO_BASE; j++){ A[i][j]='*'; } } char *pA=&A[0][0]; int i1=0; for(i1=0; i1<SO_ALTEZZA; i1++){ int j=0; for(j=0; j<SO_BASE; j++){ printf("%c" , A[i1][j]); }printf("\n"); }//da eliminare a fine progetto printf("\n"); char *Arg[]={&SO_NUM_P, &SO_BASE, &SO_ALTEZZA, pA, NULL}; char *Null[]={NULL}; int j=0; for(j=0; j<SO_NUM_G; j++){ pid_t figlio=fork(); if(figlio==0){ execve("Giocatore", Arg, Null); } else if(figlio<0){ printf("error"); } } int q=SO_NUM_P; char *k=pA; while(q>0){ char *p=posizione(SO_BASE, SO_ALTEZZA, k); int i=0; for(i=0; i<SO_ALTEZZA; i++){ int j=0; for(j=0; j<SO_BASE; j++){ if(&A[i][j]==p){ //printf("i", " ", "j", " "); k=&A[i][j]+1; } } }printf("\n \n"); q--; } int i2=0; for(i2=0; i2<SO_ALTEZZA; i2++){ int j=0; for(j=0; j<SO_BASE; j++){ printf("%c" , A[i2][j]); }printf("\n"); } } int main(){ master(); }

3rd Jan 2020, 10:42 AM
riccardo
1 Answer
+ 1
I see that you have several main() functions in this story and no returns... maybe that is the issue?
21st Mar 2020, 11:39 AM
AngryBlackSheep
AngryBlackSheep - avatar