c.str c++ code example

Example 1: strcmp c++

#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; 
}

Example 2: c c_str

Get C string equivalent

  TL;DR	->	Makes the string end with '\0'

Returns a pointer to an array that contains a null-terminated sequence of
characters (i.e., a C-string) representing the current value of the string
object.

This array includes the same sequence of characters that make up the value of
the string object plus an additional terminating null-character ('\0') at the
end.

Example 3: strcmp c++

int strcmp ( const char * str1, const char * str2 );

// returning value | indicates
// <0	the first character that does not match has a lower value in ptr1 than in ptr2
// 0	the contents of both strings are equal
// >0	the first character that does not match has a greater value in ptr1 than in ptr2

Tags:

C Example