Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int SearchLength = 0; // Defines the length of the Search input
- int ReplaceLength = 0; // Defines the length of the Replace input
- char SearchString[16]; // Saves the characters of the Search String
- char ReplaceString[16]; // Saves the characters of the Replace String
- char TempString[16];
- char input; // Defines the input by the user
- int state = 1; // state 1 = search, state 2 = replace state 3 = compare
- int forloopcounter = 0;
- int forloopcounter2 = 0;
- int TempCounter =0;
- int isTrue = 0;
- int match = 2;
- int tempcounter2 = 0;
- int main() {
- while ((input = getchar()) != '\n') {
- //case 0
- if (input == 47){
- state++;
- }
- //case 1
- if ((state == 1) && (input != 47)){
- SearchString[SearchLength] = input;
- SearchLength++;
- }
- //case 2
- if ((state == 2) && (input != 47)){
- ReplaceString[ReplaceLength] = input;
- ReplaceLength++;
- }
- if(SearchLength == 0){
- break;
- }
- if ((state == 3) && (input != 47)){
- if(TempCounter < SearchLength && match!=1 && match!=0){
- TempString[TempCounter] = input;
- TempCounter++;
- if(TempCounter == SearchLength){
- state=4;
- }
- }
- if(TempCounter < SearchLength && match == 0){
- TempString[TempCounter] = input;
- TempCounter++;
- if(TempCounter == SearchLength){
- state = 4;
- }
- }
- if(TempCounter < SearchLength && match == 1){
- TempString[TempCounter] = input;
- TempCounter++;
- if(TempCounter == SearchLength){
- state = 4;
- }
- }
- }
- if (state == 4){
- for(forloopcounter2 = 0; forloopcounter2<SearchLength; forloopcounter2++){
- if(SearchString[forloopcounter2] != TempString[forloopcounter2]){
- isTrue = 0;
- break;
- }
- else {
- isTrue = 1;
- }
- }
- if(isTrue==1){
- for(forloopcounter2 = 0; forloopcounter2 < ReplaceLength; forloopcounter2++){
- putchar(ReplaceString[forloopcounter2]);
- }
- for(forloopcounter2 = 0; forloopcounter2 < SearchLength; forloopcounter2++) {
- for (forloopcounter = 0; forloopcounter < TempCounter; forloopcounter++) {
- TempString[forloopcounter] = TempString[forloopcounter + 1];
- }
- TempCounter--;
- }
- match = 1;
- state = 3;
- }
- if(isTrue==0){
- putchar(TempString[0]);
- for(forloopcounter = 0; forloopcounter < TempCounter; forloopcounter++){
- TempString[forloopcounter] = TempString[forloopcounter+1];
- }
- TempCounter--;
- state = 3;
- match = 0;
- }
- }
- }
- if(match==0){
- for(forloopcounter =0; forloopcounter<TempCounter; forloopcounter++){
- putchar(TempString[forloopcounter]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement