Hello,
I have to write a program using exec() where user can specify the pathname and arguments. I am trying to read in the arguments in the following way:
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main()
{
...
int i;
char *cmd[100];
char argument[100];
i = 0;
for(i=0;i<3;i++)
{
printf("Enter %d. argument: ",i);
scanf("%s",argument);
cmd[i]=argument;
}
cmd[3] = (char *)0 ;
...
return 0;
}
But all I get is the last inputted argument in all 3 strings. I don't understand why. Could anyone help me with this?
Anna