Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.42 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int SearchLength = 0;   // Defines the length of the Search input
  5. int ReplaceLength = 0;  // Defines the length of the Replace input
  6. char SearchString[16];  // Saves the characters of the Search String
  7. char ReplaceString[16]; // Saves the characters of the Replace String
  8. char TempString[16];
  9. char input;             // Defines the input by the user
  10. int state = 1;          // state 1 = search, state 2 = replace state 3 = compare
  11. int forloopcounter = 0;
  12. int forloopcounter2 = 0;
  13. int TempCounter =0;
  14. int isTrue = 0;
  15. int match = 2;
  16. int tempcounter2 = 0;
  17.  
  18.  
  19.  
  20. int main() {
  21.  
  22.     while ((input = getchar()) != '\n') {
  23.  
  24.         //case 0
  25.         if (input == 47){
  26.             state++;
  27.         }
  28.  
  29.         //case 1
  30.         if ((state == 1) && (input != 47)){
  31.             SearchString[SearchLength] = input;
  32.             SearchLength++;
  33.         }
  34.  
  35.         //case 2
  36.         if ((state == 2) && (input != 47)){
  37.             ReplaceString[ReplaceLength] = input;
  38.             ReplaceLength++;
  39.  
  40.         }
  41.  
  42.         if(SearchLength == 0){
  43.             break;
  44.         }
  45.  
  46.         if ((state == 3) && (input != 47)){
  47.             if(TempCounter < SearchLength && match!=1 && match!=0){
  48.                 TempString[TempCounter] = input;
  49.                 TempCounter++;
  50.                 if(TempCounter == SearchLength){
  51.                     state=4;
  52.                 }
  53.             }
  54.             if(TempCounter < SearchLength && match == 0){
  55.                 TempString[TempCounter] = input;
  56.                 TempCounter++;
  57.                 if(TempCounter == SearchLength){
  58.                     state = 4;
  59.                 }
  60.             }
  61.             if(TempCounter < SearchLength && match == 1){
  62.                 TempString[TempCounter] = input;
  63.                 TempCounter++;
  64.                 if(TempCounter == SearchLength){
  65.                     state = 4;
  66.                 }
  67.             }
  68.         }
  69.  
  70.         if (state == 4){
  71.             for(forloopcounter2 = 0; forloopcounter2<SearchLength; forloopcounter2++){
  72.                 if(SearchString[forloopcounter2] != TempString[forloopcounter2]){
  73.                     isTrue = 0;
  74.                     break;
  75.                 }
  76.                 else {
  77.                     isTrue = 1;
  78.                 }
  79.  
  80.             }
  81.             if(isTrue==1){
  82.                 for(forloopcounter2 = 0; forloopcounter2 < ReplaceLength; forloopcounter2++){
  83.                     putchar(ReplaceString[forloopcounter2]);
  84.                 }
  85.                 for(forloopcounter2 = 0; forloopcounter2 < SearchLength; forloopcounter2++) {
  86.                     for (forloopcounter = 0; forloopcounter < TempCounter; forloopcounter++) {
  87.                         TempString[forloopcounter] = TempString[forloopcounter + 1];
  88.                     }
  89.                     TempCounter--;
  90.                 }
  91.                 match = 1;
  92.                 state = 3;
  93.  
  94.             }
  95.             if(isTrue==0){
  96.                 putchar(TempString[0]);
  97.                 for(forloopcounter = 0; forloopcounter < TempCounter; forloopcounter++){
  98.                     TempString[forloopcounter] = TempString[forloopcounter+1];
  99.                 }
  100.                 TempCounter--;
  101.                 state = 3;
  102.                 match = 0;
  103.             }
  104.         }
  105.     }
  106.     if(match==0){
  107.         for(forloopcounter =0; forloopcounter<TempCounter; forloopcounter++){
  108.             putchar(TempString[forloopcounter]);
  109.         }
  110.     }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement