answersLogoWhite

0

/* ellipses, ..., used to emulate indentation */

int strcmp (const char* s1, const char* s2) {

... while (s1 != NULL && s2 != NULL) { /* scan both strings */

... ... if (*s1 < *s2) return -1; /* first string less */

... ... if (*s1 > *s2) return 1; /* first string greater */

... ... s1++;

... ... s2++;

... }

... if (s1 == s2) return 0; /* strings equal or both empty */

... if (s1 != NULL) return 1 else return -1; /* first string longer(1) / shorter(-1) */

}

A slightly less computation-intensive version is:

int strcmp(const char* s1, const char* s2)

{

... if (s1==s2)

... ... return 0;

... while (*s1)

... ... if (*s1++^*s2++)

... ... ... if (--s1<--s2)

... ... ... ... return -1;

... ... ... else

... ... ... ... return 1;

... return 0;

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

Which operator is used to compare strings in Perl?

eq


Does C allows you to use equality operators to compare strings?

Yes, it does.


What is the use of strcmp function in c plus plus?

strcmp is used to compare two strings. If the return value is zero, the two strings are the same. If the return value is less than 0, then the first string is less than the second string, otherwise the first string is greater than the second string. Strings are compared lexicographically, character by character.


Can you tell me a C program to find if the strings are equal using pointers?

It is called strcmp, part of the standard run-time library. Returns 0 if the two strings are equals, non-zero otherwise.


What is the difference between Oracle data types char and varchar2?

Character string values storage:1. CHAR:&sect; Stores strings of fixed length.&sect; The length parameter s specifies the length of the strings.&sect; If the string has smaller length it padded with space at the end&sect; It will waste of a lot of disk space.&sect; If the string has bigger length it truncated to the scale number of the string.2. VARCHAR:&sect; Stores strings of variable length.&sect; The length parameter specifies the maximum length of the strings&sect; It stores up to 2000 bytes of characters&sect; It will occupy space for NULL values&sect; The total length for strings is defined when database was created.3. VARCHAR(2):&sect; Stores strings of variable length.&sect; The length parameter specifies the maximum length of the strings&sect; It stores up to 4000 bytes of characters&sect; It will not occupy space for NULL values&sect; The total length of strings is defined when strings are given

Related Questions

'c' code to compare two strings using strcmp function?

char one [] = "A string" ;char two [] = "Different String" ;if (strcmp (one, two) == 0){puts ("The two strings are identical") ;}else{puts ("The two strings are different") ;}


How do you campaire Strings in java?

String class in Java has an 'equals' method that can be used to compare strings.


Which operator is used to compare strings in Perl?

eq


Does C allows you to use equality operators to compare strings?

Yes, it does.


How do electric bass strings compare to upright bass strings?

Well, for one, string bass strings are a lot longer than electric bass strings. I wouldn't recommend putting string bass strings on an electric bass and vice versa.


What is the use of strcmp function in c plus plus?

strcmp is used to compare two strings. If the return value is zero, the two strings are the same. If the return value is less than 0, then the first string is less than the second string, otherwise the first string is greater than the second string. Strings are compared lexicographically, character by character.


Write a script that accepts two strings from the user and compare two strings in web technology?

how to compare two strings that take input from the user and compare it. For example: i give first string as "THE" and give second string as "HTE" then return "match" if i give first as"THE" nd second string as "EHI" then return "NOtMatch" witout using STRCMP ... please help me


How can I replace strings in a text using a specific method or function?

To replace strings in a text using a specific method or function, you can use the &quot;replace&quot; function in programming languages like Python or JavaScript. This function allows you to specify the string you want to replace and the new string you want to replace it with.


How does the size of a viola compare to that of a violin?

The viola is larger than the violin, with a longer body and longer strings.


What is the function chromatids?

Chromatids are the little strings of DNA inthe process called mitoisis


What is the the function of the heart strings?

to keep the heart open


Write a program in C to concatenante 2 strings?

Here is very small application written in C, that concatenates strings.#include #include int main() {char str[100];strcpy(str, "Hello ");strcat(str, "World!");printf("%s\n", str);return 0;}The result is "Hello World!".Concatenation is done by function strcat which is defined in string.h.