|
|
|
|
|
by tapete2
186 days ago
|
|
It doesn't even make sense to use strchr for determining the position of 'r', when the code checks that the position of '-' is at index 0. Your solution is perfectly fine. Even if you don't have access to strchr for some reason, the original snippet is really convoluted. You could just write (strlen(argv[1]) > 1 && argv[1][0] == '-' && argv[1][0] == 'r') if you really want to. |
|
And if you ever find yourself actually doing command line parsing, use getopt(). It handles all the corner cases reliably, and consistent with other tools.