Advertisement
Vprento

Исти знаци во стрингови

Dec 11th, 2017
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<ctype.h>
  5.  
  6. void compareStrings(char *s, char *k)
  7. {
  8.     int d;
  9.     if(strlen(s)>strlen(k))
  10.     {
  11.         d=strlen(s);
  12.     }
  13.     else
  14.     {
  15.         d=strlen(k);
  16.     }
  17.     int i;
  18.     for(i=0;i<d;i++)
  19.     {
  20.         if(*(s+i)==*(k+i))
  21.         {
  22.             *(s+i)=*(k+i)='*';
  23.         }
  24.     }
  25. }
  26.  
  27. int countingStars(char *s)
  28. {
  29.     int count=0;
  30.     while(*s!='\0')
  31.     {
  32.         if(*s=='*')
  33.         {
  34.             count++;
  35.         }
  36.         s++;
  37.     }
  38.     return count;
  39. }
  40.  
  41. int main()
  42. {
  43.     char s[100], k[100];
  44.     gets(s);
  45.     gets(k);
  46.     compareStrings(s, k);
  47.     printf("%d\n", countingStars(s));
  48.     puts(s);
  49.     puts(k);
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement