Advertisement
villers

Untitled

Oct 7th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. /*
  2. ** my_strncmp.c for J06 in /home/viller_m/rendu/Piscine_C_J06
  3. **
  4. ** Made by mickael villers
  5. ** Login <[email protected]>
  6. **
  7. ** Started on Mon Oct 6 14:08:02 2014 mickael villers
  8. ** Last update Mon Oct 6 14:39:25 2014 mickael villers
  9. */
  10.  
  11. int my_strncmp(char *s1, char *s2, int n)
  12. {
  13. int i;
  14.  
  15. i = 0;
  16. while (s1[i] == s2[i] && s1[i] && s2[i] && i < n)
  17. {
  18. i = i + 1;
  19. }
  20. if ((s1[i] == '\0' && s2[i] == '\0') || i == n)
  21. {
  22. return (0);
  23. }
  24. else if (s1[i] > s2[i])
  25. {
  26. return (1);
  27. }
  28. else
  29. {
  30. return (-1);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement