How do I handle argv character array assignments?
argv, c
Solution
The reason s1 works is because the type of argv[0] is a pointer. You are simply assigning the address (not the actual value), which is safe. You aren't performing any kind of allocation or cast.
I typically prefer the first option as you should only be reading from the argument variables.
Problem
I found two ways of passing command-line arguments into a character array: ``` 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 nice because argv[0] can be any length. s2 requires that the length of argv[0] < 256 characters. I do not understand how/why s1 should work. I think the right-hand side of s1 should be required at compile time, but I think it's generated at run-time.