Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a C programming question. I am trying to understand the logic behind the

ID: 3826981 • Letter: I

Question

I have a C programming question. I am trying to understand the logic behind the strcmp function.

say you have a piece of code that looks like this

string1 = "abcde";

string2 = "ABCDE";

strcmp(string1, string2);

It is my understanding that string 1 is less than string2 to however, I need to know what makes string1 less than string2. Can someone please explain the logic beghind strcmp function as well as what makes "abcde" less than "ABCDE"? Does it have anything to do with the ASCII table?

Please be specific.

Explanation / Answer

Answer: strcmp method will compare the each and every chracter in both strings unless there is mismatch between two corresponding characters. If any mismatch between two corresponding characters then it will return first mismacth characters ascii values difference otherwise it will return 0. I mean if there is no mismatch between to strings then it will return 0.

Does it have anything to do with the ASCII table?

Yes. strcmp will deal with ASCII table values only.