strcmp

Solutions on MaxInterview for strcmp by the best coders in the world

showing results for - "strcmp"
Louella
04 Feb 2020
1#include<stdio.h> 
2#include<string.h> 
3
4
5int main() 
6{  
7      
8    char char1[] = "coucou"; 
9    char char2[] = "coucou"; 
10      
11  	if( strcmp(char1, char2) == 0 )
12       printf("Strings are the same");
13  
14  	else
15      prinf("Strings are differentes");
16  
17  
18    return 0; 
19}
Alexander
12 Aug 2016
1return
2	>0 if first string is large
3    <0 if first string is short
4     0 if strings are equal
5    
6int strcmp ( const char * str1, const char * str2 );
Alessandra
16 Oct 2017
1THINK STRING_1 - STRING_2
2
3strcmp("ab",  "ac");  /* = -1 */
4strcmp("abc", "ab");  /* =  1 */
5strcmp("abc", "abc"); /* =  0 */
Lennart
17 Jul 2017
1#include <string.h>
Cillian
14 Sep 2019
1STRCMP (const char *p1, const char *p2)
2{
3  const unsigned char *s1 = (const unsigned char *) p1;
4  const unsigned char *s2 = (const unsigned char *) p2;
5  unsigned char c1, c2;
6  do
7    {
8      c1 = (unsigned char) *s1++;
9      c2 = (unsigned char) *s2++;
10      if (c1 == '\0')
11        return c1 - c2;
12    }
13  while (c1 == c2);
14  return c1 - c2;
15}