Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <stdlib>
- #include <stdio>
- #include <windows>
- #include <locale>
- /////////////////////////////////////////////////
- int main (void)
- {
- setlocale(LC_ALL, "Russian");
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- setlocale(LC_CTYPE, "rus");
- system("color 0F");
- char q[255]; // Modified string
- // Origin string
- char w[]= "He can't hurt you more. Baby, Baby as he did before. Come on, Baby, keep your hands of him. In the gipsy night";
- // Preset words
- char wordHi[] = "Baby"; char wordLow[] = "Honey";
- // Print origin string
- printf(w); printf("\n\n");
- // Character pointers
- char *p; char *pp;
- // First occurrence of a word in a string
- p = strstr(w, wordHi);
- if (p!=NULL)
- {
- // We form a new line
- *p= '\0'; strcpy(q,w); strcat(q,wordLow);
- *p= ' ';
- p= p + strlen(wordHi);
- pp= p;
- /* Modification of the original string
- by deleting viewed characters */
- int qq=0;
- while (qq<strlen(w))
- { w[qq]= *pp;
- pp++;
- qq++;
- }
- }
- // Subsequent occurrences of a word in a string
- Next: p = strstr(w, wordHi);
- if (p==NULL) { strcat(q,w); goto ENDEND; } // New line created
- else
- {
- // We form a new line
- *p= '\0';
- strcat(q,w);
- strcat(q,wordLow);
- *p= ' ';
- p= p + strlen(wordHi);
- pp= p;
- /* Modification of the original string
- by deleting viewed characters */
- int qq=0;
- while (qq<strlen(w))
- {
- w[qq]= *pp;
- pp++;
- qq++;
- }
- goto Next;
- }
- ENDEND:
- printf(q); printf("\n\n"); // New line on the screen
- //printf(w); printf("\n\n"); // This original line was destroyed.
- printf("\n");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement