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

  • Thread starter Thread starter zeion
  • Start date Start date
  • Tags Tags
    Pointers Stupid
AI Thread Summary
The discussion centers around the use of the `strcmp` function in C for comparing strings stored in a pointer array. The original poster is confused about how to check if a specific argument exists within the array using `strcmp`. The key point clarified is that `strcmp` requires string arguments, meaning the comparison should be made between `ptr[i]` and `"a"` (a string) rather than `'a'` (a character). This distinction is crucial for the function to work correctly, as `strcmp` operates on `char*` pointers representing strings. The original poster expresses frustration over this misunderstanding, realizing that their debugging efforts were misdirected due to this error.
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
 
Technology 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!
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Back
Top