Ive been given this code in class:
int main(int argc, char **argv)
{
if(argc)
{
return 1;
}
puts(argv[3]);
return 0;
}
Now, Im supposed to write a second program which executes this and makes it print "Hello World!". So I have to find a way to pass in arguments (I assume with execv) while having argc stay at 0.
This is what I have so far:
int main()
{
pid_t pid = fork();
if(pid == 0)
{
char *argv[] = { "filepath", "placeholder",
"placeholder", "Hello World!" };
execv("filepath", argv);
exit(0);
}
else
{
waitpid(pid, 0, 0);
}
return 0;
}
This is going to run on Linux.
I tried mbj's original suggestion to pass a 0 in the arguments array, which sadly didnt work. However if I put 0 as the first argument, argc becomes 0, but then I get the output "LC_MEASUREMENT=de_DE.UTF-8" when trying to print the arguments. Googling this didnt really help me either.
Im at a total loss here, so any help is appreciated.