estephane

ponteiros2

Oct 30th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6.  
  7.  
  8. int compare(char* str1, char* str2);
  9.     int main()
  10. {
  11.     char str1[40],str2[40];
  12.  
  13.     int retorno;
  14.  
  15.     printf("Digite uma string:");
  16.     scanf("%s%s",str1,str2);
  17.     compare(str1,str2);
  18.  
  19.  
  20.     return 0;
  21. }
  22.  
  23. int compare(char* str1, char* str2)
  24. {
  25.     int i,j,tamanho1,tamanho2,cont=0;
  26.     tamanho1 = strlen(str1);
  27.     tamanho2 = strlen(str2);
  28.     for(i=0;i<=tamanho1;i++)
  29.     {
  30.         if((str1[i])==(str2[i]))
  31.         {
  32.             cont+=1;
  33.  
  34.         }
  35.         if(str1[i]!=str2[i])
  36.         {
  37.             break;
  38.         }
  39.  
  40.     }
  41.  
  42.     if((cont-1)==tamanho1)
  43.         printf("\nSao iguais: %d",0);
  44.     if((tamanho1>tamanho2) ||(tamanho1<tamanho2))
  45.         printf("\nNao sao iguais%d",1);
  46.  
  47.  
  48.  
  49. }
  50.  
  51.  
  52. /*
  53. void load(int* n);
  54.  
  55. int main()
  56. {
  57.     int i;
  58.     int n[10];
  59.     for(i=0;i<10;i++)
  60.     {
  61.         n[i] = 0;
  62.     }
  63.  
  64.     for(i=0;i<10;i++)
  65.     {
  66.         printf("\nV1:%d", n[i]);
  67.     }
  68.  
  69.     load(n);
  70.  
  71.      for(i=0;i<10;i++)
  72.     {
  73.         printf("\nV2:%d", n[i]);
  74.     }
  75. }
  76.  
  77.  
  78. void load(int* n)
  79. {
  80.     int i;
  81.     srand(time(NULL));
  82.    for(i=0;i<10;i++)
  83.    {
  84.        n[i] = (1+(rand()%6));
  85.    }
  86.  
  87. }
  88.  
  89. */
Advertisement
Add Comment
Please, Sign In to add comment