Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

strcmp.c (675B)


      1 #include "../include/strcmp.h"
      2 #include "../include/print.h"
      3 
      4 int strcmp (const char *st1, const char *st2) {
      5     int len1 = 0, len2 = 0, foundLen = 0;
      6     int foundFlag = 0;
      7     const char *p1 = st1;
      8     const char *p2 = st2;
      9     while (*p1 != 0) {
     10         len1++;
     11         p1++;
     12     }
     13     while (*p2 != 0) {
     14         len2++;
     15         p2++;
     16     }
     17     if (len1 == len2) {
     18         p1 = st1;
     19         p2 = st2;
     20 
     21         while (*p1 != '\0') {
     22             if (*p1 != *p2) {
     23                 return -1;
     24             }
     25             foundLen++;
     26             p1++;
     27             p2++;
     28         }
     29 
     30         if (len1==foundLen) {
     31             return 1;
     32         } else return -1;
     33     } return -1;
     34 }