Cstring.h-strcmp()
The built-in library function strcmp() is listed in the header file "string.h".The two strings are compared via strcmp(). Lexicographically speaking, this refers to comparing characters one at a time beginning with the first character until both strings of characters have the same length or a NULL character is met.
SYNTAX
The following is the syntax of strcmp() function:-
int strcmp(string leftStr, string rightStr );
PARAMETER
It takes two string as arguments and compares the string according to lexicographical order.
OUTPUT
It returns a positive value if first string is higher the lexicographical order, return zero if they are same and negative value if the first string is lower in the lexicographical order
CODE
// Use of strcmp() in C++
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main()
{
char s1[] = "string1";
char s2[] = "string2";
int c=strcmp(s1,s2);
cout<<" \n Difference between strings are = "<<c<<endl;
return 0;
}
OUTPUT
Name | Views | Likes |
---|---|---|
Cstring-strcspn() | 140 | 0 |
Cstring.h-strcmp() | 216 | 0 |
Cstring.h-strcpy() | 153 | 0 |
Cstring.h-strlen() | 178 | 0 |
Cstring.h-strpbrk() | 124 | 0 |
Cstring.h-strrchr() | 107 | 0 |
Ctype.h – toupper() | 115 | 0 |
Ctype.h- tolower() | 124 | 0 |
Ctype.h – isxdigit() | 144 | 0 |
Ctype.h – isupper() | 115 | 0 |
Ctype.h- isspace() | 125 | 0 |
Ctype.h- ispunct() | 123 | 0 |
Ctype.h- isprint() | 104 | 0 |
Ctype.h- islower() | 132 | 0 |
Ctype.h- isdigit() | 129 | 0 |
Ctype.h- iscntrl() | 111 | 0 |
Ctype.h – isblank() | 122 | 0 |
Ctype.h – isalpha() | 129 | 0 |
Ctype.h- isalnum() | 122 | 0 |
INTRODUCTION OF ctype.h LIBRARY | 106 | 0 |
EVENT LISTENER | 129 | 0 |
Using Mixins with Eventdispacher | 103 | 0 |
INTRODUCTION TO MIXINS | 136 | 0 |
Call Back function | 149 | 0 |
Eventpp Library | 287 | 0 |
Comments