Semester : S1 and S2
Subject : Computer Programming
Year : 2018
Term : MARCH
Branch : BIOTECHNOLOGY
Scheme : 2015 Full Time
Course Code : CS 100
Page:14
char *string1 ="LearnC Online"; char
*string2 = ""LearnC Online"; int ret;
ret=strcmp(string1, string2); = printf("%d", ret);
Output:
0
f)strncmp()
strncmp() is used to compare only left most ന് characters from the strings.
Syntax: 17 strncmp(string1, string2,no_of_chars);
This function returns integer value after comparison.
Value returned is 0 if left most ‘n’ characters of two strings are equal.
If the left most ‘n’ characters of first string is alphabetically greater than the left most ‘n’ characters of
second string then, it returns a positive value.
If the left most ‘n’ characters of first string is alphabetically less than the left
most ‘n’ characters of second string then, it returns a negative value Example:
char *string1 = "Learn © Online is a great 5161; char *string2 = "Learn © Online";
int ret;
ret=strncmp(string1, string2,7); = printf("%d",ret);
char *string1 ="LearnC Online is a great site"; char
*string2 = صعوعا" Online"; int ret;
ret=strncmp(string1, string2,7); = printf("%d" ret);
Output:
0
£) strcmpi() | strcmpi() function is use two compare two strings. strcmp() function does a case
insensitive comparison between two strings. The Destination_String and
Source_String can either be a string constant or a variable.
Syntax: int strcmpi(string1,
string2);
This function returns integer value after comparison.
Example: char *string1 = “Learn ©
Online”;
char *string2 =“LEARN CONLINE”; _ int ret;
ret=strcmpi(string1, string2);
printf("%d", ret);
char *string1 = “Learn © Online”;
char *string2 =“LEARN CONLINE”; _ int ret;
ret=strcmpi(string1, 51111६2); printf("%d", ret);
Output:
0
h) strncmpi() ടനന്ധാി() is used to compare only left most ന characters from the strings. strncmpi()
function does a case insensitive comparison.
Syntax: int strncmpi(string1, string2,no_of_chars);
This function returns integer value after comparison.
Example: char *string1 = "Learn © Online is a great site";
char *string2 ="LEARN ೮ ONLINE"; _ int ret;
ret=strncmpi(string1, string2,7); = printf("%d",ret);
char *string1 ="LearnC Online is a great site"; char
*string2 = "LEARN © ONLINE"; _ int ret;