StudentSeng

stringcmp

Oct 27th, 2020
1,692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. include<stdio.h>
  2.  
  3. int stringcmp(char *s1, char *s2);
  4.  
  5. int main()
  6. {
  7.     printf("%d", stringcmp("test", "testing"));
  8. }
  9.  
  10. int stringcmp(char *s1, char *s2)
  11. {
  12.     int i = 0;
  13.     do
  14.     {
  15.         printf("%c, %c\n", s1[i], s2[i]);
  16.         if ((int)s1[i] > (int)s2[i])
  17.             return 1;
  18.         else if ((int)s1[i] < (int)s2[i])
  19.             return -1;
  20.         i++;
  21.     }
  22.     while (s1[i-1] != '\0' && s2[i-1] != '\0');
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment