Advertisement
Guest User

STRCMP

a guest
Jan 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdint.h"
  3. #include "inttypes.h"
  4. #include "stdio.h"
  5.  
  6. int mystrcmp(const char *str1, const char *str2) {
  7. int ans = 0;
  8. while (*str1 != '\0' && *str2 != '\0') {
  9. unsigned char a = *str1;
  10. unsigned char b = *str2;
  11. if (a > b) {
  12. ans = 1;
  13. return ans;
  14. } else if (a < b) {
  15. ans = -1;
  16. return ans;
  17. }
  18. ++str1;
  19. ++str2;
  20. }
  21. if (*str1 == '\0' && *str2 != '\0') {
  22. ans = -1;
  23. } else if (*str2 == '\0' && *str1 != '\0') {
  24. ans = 1;
  25. }
  26. return ans;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement