I found two ways to pass command line arguments to an array of characters:
int main (int argc, char **argv)
{
const char *s1 = argv[0];
char s2[256];
strcpy(s2, argv[0]);
printf("s1: %s\ns2: %s\n\n", s1, s2);
}
Compiled with the IBM xlc compiler on an AIX system. Returns
[MyPrompt]> ./a.out
s1: ./ a.out
s2: ./ a.out
Which implementation (s1 or s2) is correct? s1 is good because argv [0] can be any length. s2 requires a length of argv [0] of 256 characters.
I do not understand how / why s1 should work. I think the right side of s1 should be required at compile time, but I think that it was generated at runtime.
source
share