Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
56
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<string.h>
  3.  
  4. bool isInMultiple(char *word1, char *word2){
  5.     int count =0;
  6.     char *temp = word1;
  7.     for (int i=0;i<strlen(word1);i++){
  8.             if (strncmp(&temp[i], word2, 3) == 0)
  9.                 count++;
  10.             if (count >=2)
  11.                 return true;
  12.     }
  13.     return false;
  14. }
  15.  
  16. int main (){
  17.     char *word1 = "rskrskrsk";
  18.     char word2 [4] = {0};
  19.  
  20.     char* checkedStrings = {0};
  21.    
  22.     char *temp = word1;
  23.     char char1, char2, char3;
  24.  
  25.     int count =0;
  26.     for (int i = 0; i < (strlen(word1)-3); ++i){
  27.         count = 0;
  28.         strncpy(word2, &temp[i], 3);
  29.         word2[3] = '\0';
  30.        
  31.         temp = word1;
  32.  
  33.         if (!strncmp(checkedStrings, word2, 3) && isInMultiple(word1, word2)){
  34.             printf("%s\n", word2);
  35.             strcat(checkedStrings, word2);
  36.         }
  37.  
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement