aboutsummaryrefslogtreecommitdiff
path: root/src/strcmp.c
diff options
context:
space:
mode:
authorNicholas Hall <ngh@grandcare.com>2017-09-14 16:42:29 -0500
committerNicholas Hall <ngh@grandcare.com>2017-09-14 16:42:29 -0500
commit52e3ab594b34bf309b8669fcaa855c295a00e114 (patch)
tree464216f7987f6df92d7c2c85bf3d398ef32189ea /src/strcmp.c
downloadhooking_strcmp-52e3ab594b34bf309b8669fcaa855c295a00e114.tar.xz
hooking_strcmp-52e3ab594b34bf309b8669fcaa855c295a00e114.zip
DC414 meeting presentation filesHEADmaster
Diffstat (limited to 'src/strcmp.c')
-rw-r--r--src/strcmp.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/strcmp.c b/src/strcmp.c
new file mode 100644
index 0000000..d626bd3
--- /dev/null
+++ b/src/strcmp.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+/* Compare S1 and S2, returning less than, equal to or
+ greater than zero if S1 is lexicographically less than,
+ equal to or greater than S2. */
+int strcmp (const char *p1, const char *p2)
+{
+ const unsigned char *s1 = (const unsigned char *) p1;
+ const unsigned char *s2 = (const unsigned char *) p2;
+ unsigned char c1, c2;
+
+ // print out input values
+ printf("strcmp('%s', '%s')", p1, p2);
+ do
+ {
+ c1 = (unsigned char) *s1++;
+ c2 = (unsigned char) *s2++;
+ if (c1 == '\0') {
+ // print return value
+ printf(" = %d\n", c1 - c2);
+ return c1 - c2;
+ }
+ }
+ while (c1 == c2);
+
+ printf(" = %d\n", c1 - c2);
+ return c1 - c2;
+}