Questions tagged [strcmp]

strcmp is a string compare function that is available in languages such as C, C++, PHP, Python and MATLAB.

strcmp is a string compare function that is available in languages such as C, C++, PHP, Python and MATLAB.

Structure

PHP
int strcmp ( string $str1 , string $str2 )
C
int strcmp( const char *lhs, const char *rhs );

Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

Examples

PHP
echo strcmp("a","z"); // returns a negative number
echo strcmp("a","a"); // returns 0
echo strcmp("z","a"); // returns a positive number
C
int res = strcmp("a", "z"); // result is a negative number
int res = strcmp("a", "a"); // result is 0
int res = strcmp("z", "a"); // result is a positive number

References

https://en.cppreference.com/w/cpp/string/byte/strcmp

949 questions
-7
votes
1 answer

strcmp always returns 1 even if it ie equal

it always returns 1 even if they aren't same and im wondering that why i have to write down buffer size in scanf_s if i don't the scnaf_s does not work int main(void) { char str1[30] = "push"; char str2[30] = { 0 }; scanf_s("%s",…
-8
votes
1 answer

Push pop stack operation in C

I tried to make a stack push pop operations with storing values from pop in an array. I have a few questions for this code. 1. Does the initialization part work well? When compiling, it seems there is no problem but I'm still curious. 2. Does the…
stella
  • 25
  • 1
  • 8
-10
votes
2 answers

Please Help me about "strcmp"

I have slice of C code and I want to ask when I input some string for example "up". Jump to the code looks like : (strcmp(pdirection,"up")==0) So, what does it mean, I don't understand especially ==0 the slice of code is at call by reference…
Shawn
  • 23
  • 5
-20
votes
4 answers

How to check if `strcmp` has failed?

Well this question is about C and C++ as strcmp is present in both of them. I came across this link: C library function - strcmp(). Over here it was explained the return values of strcmp. I know that every function, how much ever safe it is, can…
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
1 2 3
63
64