Hi guys,
I'm having a weird error that I can't understand why:
My program is the following:
int paralelo(int num)
{
int cont,pid;
printf("Creating %d sons with pid\n", num);
for(cont=0;cont<num;cont++)
{
pid=fork();
if(pid==0)
{
printf("I'm the son number %d e %d\n", cont, getpid());
exit(0);
}
}
return(0);
}
int main(int argc, char* argv[])
{
int k=0, j, i, x, m, n,status, cont;
char* comandi[256];
k=atoi(argv[1]);
for(cont=0;cont<k;cont++)
{
strncpy(comandi[cont], argv[cont+1], sizeof(comandi[n]));
}
x=paralelo(k);
}
The problem comes when I execute the program:
./program 3 file1 file2 fil3
When I put as argv[1] any number, I get a segmentation fault. If I don't use any numbers I don't get any errors. But why ? I'm supposed to execute the program giving the program name, a constant ( argv[1] ) and then "n" file names.
Why am I getting this error ? It could be because Im using portable ubuntu on windows or I'm saying non senses ?
thanks