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

  • Thread starter Thread starter zeion
  • Start date Start date
  • Tags Tags
    Pointers Stupid
Click For Summary
SUMMARY

The discussion centers on the use of the strcmp function in C programming to compare strings stored in a char **ptr pointer. The user initially attempted to compare a string with a character, which led to confusion. It is clarified that strcmp requires two string arguments, and the correct usage involves using double quotes for strings, such as "a", rather than single quotes for characters, like 'a'. This distinction is crucial for proper string comparison in C.

PREREQUISITES
  • C programming language fundamentals
  • Understanding of pointers and memory management in C
  • Knowledge of string handling functions in C, specifically strcmp
  • Familiarity with character vs. string data types in C
NEXT STEPS
  • Study the strcmp function in the C Standard Library
  • Learn about string manipulation functions in C, such as strcpy and strlen
  • Explore pointer arithmetic and its applications in C programming
  • Practice debugging techniques for C programs involving strings and pointers
USEFUL FOR

This discussion is beneficial for C programmers, particularly beginners who are learning about string manipulation and pointer usage. It is also useful for anyone looking to improve their debugging skills in C.

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!
 

Similar threads

  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 118 ·
4
Replies
118
Views
10K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 19 ·
Replies
19
Views
4K
  • · Replies 2 ·
Replies
2
Views
11K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 75 ·
3
Replies
75
Views
6K
  • · Replies 12 ·
Replies
12
Views
3K