strcmp char code example
Example 1: strcmp c
// use: strcmp(string1, string2);
string a = "words";
string b = "words";
if (strcmp(a, b) == 0)
{
printf("a and b match");
// strcmp returns 0 if both strings match
}
else
{
printf("a and b don't match");
// strcmp returns anything else if the strings dont match
}
Example 2: strcmp c++
#include
#include
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 3: compare two chars c
strcmp(char, char);