Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main()
  5. {
  6. char string1[20], string2[20];
  7.  
  8. printf("Primeira string:\n");
  9. gets(string1);
  10.  
  11. printf("Segunda string:\n");
  12. gets(string2);
  13.  
  14. if (comparar_strings(string1, string2) == 0)
  15. printf("Sao iguais!\n");
  16. else
  17. printf("Sao diferentes!\n");
  18.  
  19. return 0;
  20. }
  21.  
  22. int comparar_strings(char string1[], char string2[]){
  23. int c = 0;
  24.  
  25. while (string1[c] == string2[c]) {
  26. if (string1[c] == '\0' || string2[c] == '\0')
  27. break;
  28. c++;
  29. }
  30.  
  31. if (string1[c] == '\0' && string2[c] == '\0')
  32. return 0;
  33. else
  34. return -1;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement