0

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

2
  • What errors do you get if you try to use str? Assuming check_flag is called with argv[1] in main based on the comment "Returns true if str is a valid flag (-a, -b, -r, or -s), false otherwise" – DinoCoderSaurus May 4 '17 at 21:34
  • helpers.c:20:13: error: result of comparison against a string literal unspecified (use strncmp instead) [-Werror,-Wstring-compare] if (str == "-a") ^ ~~~~ 1 error generated. make: *** [race] Error 1 im gonna work with strncpy for a bit, thanks man, – G-REG May 4 '17 at 21:48
1

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).

1
  • Awesome!! Thanks for the direction Dino. Just what i needed. – G-REG May 5 '17 at 0:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .