I\'m writing a program to check to see if a port is open in C. One line in particular copies one of the arguments to a char array. However, when I try to compile, it says:
an alternative is to use a char * instead:
char *addr;
addr = strdup(argv[2]);
strdup is basically a shortcut that does a malloc and a strcpy, and you don't have to worry about the size of addr upfront.
Don't forget to free addr once you're done.
Note that if argv[2] is NULL you will get a segfault.