0

According to K&R, strcmp cab be used to compare two lines, lexicographically. (p.119)

They use another function, numcmp, to compare two lines numerically. However, aren't these two descriptions basically the same?

Isn't the Lexicographic order of ASCII characters the order in which they appear on the list, which is determined by their machine integer value? That would mean that numcmp and strcmp are basically identical.

Edit:

When they say the numeric value of a line, do they mean adding up the ASCII integer values of all of the characters in the line?

Edit:

I'm not sure why my question is getting thumbed down. Should I inherently know what the numeric value of a line means?

asked Sep 12, 2014 at 5:11
4
  • "11" should be larger because isn't the second "1" compared to '0円'? Commented Sep 12, 2014 at 5:19
  • "numeric value of a line" means that 123 has value of the number 123 Commented Sep 12, 2014 at 5:52
  • Do you mean "123" is numerically 123? If so, what if the string elements are not digits? Commented Sep 12, 2014 at 6:39
  • 1
    Then there would be no numeric value. Commented Sep 12, 2014 at 6:49

1 Answer 1

10

5 is numerically less than 10, but "10" is lexicographically less than "5".

answered Sep 12, 2014 at 5:15
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.