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

  • Thread starter Thread starter zeion
  • Start date Start date
  • Tags Tags
    Pointers Stupid
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
zeion
Messages
455
Reaction score
1
Hi,

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?

Thanks
 
Physics news on Phys.org
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').
 
DrGreg said:
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').


Nooo wayyy I've been trying to debug that the whole day!