Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[C] Stupid pointers what the heck is going on here

  1. Jul 14, 2012 #1

    I don't understand how this can be so difficult.
    So I have a [char ** ptr] pointer that stores a list of arguments.
    I'm able to PRINT each of them by doing printf("%s\n", ptr)
    But how the heck do I is strcmp to see if a certain argument is there?
    Apparently I cannot just do [if (strcmp(ptr, 'a') == 0].
    I don't understand what strcmp needs for it to work. Do I need one star? Two stars? Five stars? Why is this so hard?

  2. jcsd
  3. Jul 14, 2012 #2


    User Avatar
    Science Advisor
    Gold Member

    strcmp compares strings (via char* pointers). Your problem is not with ptr but with 'a' which is not a string, but a character. "a" is a string (consisting of one character 'a').
  4. Jul 14, 2012 #3

    Nooo wayyy I've been trying to debug that the whole day!!!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook