eg0rmaffin

strcmp

Sep 3rd, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1.  
  2.  
  3. #include <stdio.h>
  4.  
  5.  
  6.  
  7.  
  8. int ft_strcmp(char *s1, char *s2)
  9. {
  10.     int run = 0;
  11.     int res;
  12.    
  13.     while ((s1[run] != '\0') && (s2[run] != '\0'))
  14.     {
  15.         if (s1[run] == s2[run])
  16.             run++;
  17.         else if (s1[run] != s2[run])
  18.         {
  19.             res = s1[run] - s2[run];
  20.             return res;
  21.         }
  22.     }
  23.     return 0;
  24. }
  25.  
  26. int main()
  27. {
  28.     char *s1;
  29.     char *s2;
  30.    
  31.     s1 = "huu";
  32.     s2 = "hui";
  33.    
  34.     printf("%d", ft_strcmp(s1, s2));
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment