nikolas_serafini

Lista 7 - Exercício 10

Aug 10th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int neoStrlen(char test[]);
  5. void neoStrcpy(char test[], char test2[]);
  6. int neoStrcmp(char test[], char test2[]);
  7.  
  8. int main() {
  9.     char testString[20],testString2[20];
  10.  
  11.     printf("Entre com uma string:\n");
  12.     gets(testString);
  13.     printf("Entre com outra string:\n");
  14.     gets(testString2);
  15.  
  16.     printf("Quantidade de caracteres da primeira string : %d\n",neoStrlen(testString));
  17.     printf("Quantidade de caracteres da segunda string : %d\n",neoStrlen(testString2));
  18.     printf("0(iguais), -1(primeira < segunda), 1(primeira > segunda) : %d\n",neoStrcmp(testString,testString2));
  19.     neoStrcpy(testString,testString2);
  20.     printf("Teste de copia (segunda string para perimeira) -> %s\n",testString);
  21.  
  22.     printf("Ira aparecer 0 se ambas forem iguais : %d\n",neoStrcmp(testString,testString2));
  23.  
  24.     return 0;
  25. }
  26.  
  27. int neoStrlen(char test[]) {
  28.     int i = 0,counter = 0;
  29.  
  30.     while (test[i++] != '\0')
  31.         counter++;
  32.  
  33.     return counter;
  34. }
  35.  
  36. void neoStrcpy(char test[], char test2[]) {
  37.     int i = 0;
  38.  
  39.     while (test[i] != '\0' || test2[i] != '\0') {
  40.         test[i] = test2[i];
  41.         i++;
  42.     }
  43. }
  44.  
  45. int neoStrcmp(char test[], char test2[]) {
  46.     int i = 0;
  47.  
  48.     while (test[i] != '\0') {
  49.         if (test[i] > test2[i])
  50.             return 1;
  51.         else if (test[i] < test2[i])
  52.             return -1;
  53.         else
  54.             i++;
  55.     }
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment