I have a quick question about the check_flag function in sort race. Just looking for a hint or advice to lead me in the right direction. I cant quite figure out how to reference the argv[1] values. I get errors when i try to use argv[1], also if i try to str. There is no main in helpers.c, so i am wondering where the flag values are at this point in the process. Thanks so much for any consideration, I'm new to this, so sorry if i missed any protocols in this question. G-REG
1 Answer
The code comment "Returns true if str is a valid flag (-a, -b, -r, or -s), false otherwise" indicates you would use str
to determine validity. In C, strings cannot be compared directly as in if (str == "-a")
or you will get the error error: result of comparison against a string literal unspecified (use strncmp instead)
as mentioned in the comment. You would need to use the strcmp
function, which you can review with man strcmp
. Or perhaps recall initials
and caesar
where strings were processed as individual characters (hint, hint).
str
? Assuming check_flag is called withargv[1]
in main based on the comment "Returns true if str is a valid flag (-a, -b, -r, or -s), false otherwise"