Guest User

Untitled

a guest
Apr 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. char texto1[] = "um texto";
  2. char texto2[] = "um texto";
  3.  
  4. printf("n%d", texto1 == texto2); //0 - que representa falso
  5.  
  6. char *texto3 = texto1;
  7. printf("n%d", texto1 == texto3); //1 - que representa verdadeiro
  8.  
  9. int compara_strings(char str1[], char str2[]){
  10. int i;
  11. for (i = 0; str1[i] != '' && str2[i] != ''; i++){
  12. //assim que uma letra seja diferente
  13. if (str1[i] != str2[i]){
  14. //retorna -1 se a primeira for menor ou 1 caso contrário
  15. return str1[i] < str2[i] ? -1 : 1;
  16. }
  17. }
  18. //Se as duas acabaram, são iguais e retorna 0. Se a str1 acabou e str2 não
  19. //retorna um valor negativo. Se str2 acabou e a str1 retorna um valor positivo
  20. return str1[i] - str2[i];
  21. }
  22.  
  23. char texto1[] = "um texto";
  24. char texto2[] = "um texto";
  25.  
  26. printf("n%d", strcmp(texto1,texto2)); //0 - que representa iguais
Add Comment
Please, Sign In to add comment