"String Comparisons" Please respond to the following:

Computer Science
Tutor: None Selected Time limit: 1 Day

Contrast the differences between the strcasecmp() and strcmp() function. Provide an example of each to show their usage.

Jan 26th, 2015

Both trcasecmp() and strcmp() functions compare two strings. strcmp() compares the entire string down to the end, while strncmp() only compares the first n characters of the strings.

It's a little funky what they return. Basically it's a difference of the strings, so if the strings are the same, it'll return zero (since the difference is zero). It'll return non-zero if the strings differ; basically it will find the first mismatched character and return less-than zero if that character in s1 is less than the corresponding character in s2. It'll return greater-than zero if that character in s1 is greater than that in s2.

For the most part, people just check to see if the return value is zero or not, because, more often than not, people are only curious if strings are the same.


Jan 26th, 2015

Are you studying on the go? Check out our FREE app and post questions on the fly!
Download on the
App Store
...
Jan 26th, 2015
...
Jan 26th, 2015
Dec 11th, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer