strcmp

THINK STRING_1 - STRING_2

strcmp("ab",  "ac");  /* = -1 */
strcmp("abc", "ab");  /* =  1 */
strcmp("abc", "abc"); /* =  0 */

3.63
8
Phoenix Logan 186120 points

                                    #include<stdio.h> 
#include<string.h> 


int main() 
{  
      
    char char1[] = "coucou"; 
    char char2[] = "coucou"; 
      
  	if( strcmp(char1, char2) == 0 )
       printf("Strings are the same");
  
  	else
      prinf("Strings are differentes");
  
  
    return 0; 
}

3.63 (8 Votes)
0
3.89
9
Phoenix Logan 186120 points

                                    #include <string.h>

3.89 (9 Votes)
0
3.67
3
Awgiedawgie 440220 points

                                    return
	>0 if first string is large
    <0 if first string is short
     0 if strings are equal
    
int strcmp ( const char * str1, const char * str2 );

3.67 (3 Votes)
0
3.78
9
Phoenix Logan 186120 points

                                    STRCMP (const char *p1, const char *p2)
{
  const unsigned char *s1 = (const unsigned char *) p1;
  const unsigned char *s2 = (const unsigned char *) p2;
  unsigned char c1, c2;
  do
    {
      c1 = (unsigned char) *s1++;
      c2 = (unsigned char) *s2++;
      if (c1 == '\0')
        return c1 - c2;
    }
  while (c1 == c2);
  return c1 - c2;
}

3.78 (9 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source