1
2// syntax
3#include <cstring> // this needs to be at the top of the script/code
4std::strcmp(<1st-char>,<2nd-char>)
5
6// example (assuming: char_1 = 'Compare me'; char_2 = 'Compare_me')
7#include <cstring>
8if (std::strcmp(char_1,char_2) == 0) {
9 std::cout << "The char's that you compared match!" << std::endl;
10}
11else {
12 std::cout << "The char's that you compared DON'T match" << std::endl;
13}
14
15// OUTPUT: The char's that you compared match!
16
17/*
18NOTE: the following outputs of std::strcmp indicate:
19[less than zero] : left-hand-side appears before right-hand-side in lexicographical order
20[zero] : the chars are equal
21[greater than zero] : left-hand-side appears after right-hand-side in lexicographical order
22*/
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}
1#include <string.h>
2...
3if (strcmp(firstSTR, secondSTR) == 0) {
4 // strings are equal
5 ...
6} else {
7 // strings are NOT equal
8}