Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <string>
  2. #include <stdlib>
  3. #include <stdio>
  4. #include <windows>
  5. #include <locale>
  6.  
  7. /////////////////////////////////////////////////
  8. int main (void)
  9. {
  10. setlocale(LC_ALL, "Russian");
  11. SetConsoleOutputCP(1251);
  12. SetConsoleCP(1251);
  13. setlocale(LC_CTYPE, "rus");
  14.  
  15. system("color 0F");
  16.  
  17. char q[255]; // Modified string
  18.  
  19. // Origin string
  20.  
  21. 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";
  22.  
  23. // Preset words
  24.  
  25. char wordHi[] = "Baby"; char wordLow[] = "Honey";
  26.  
  27. // Print origin string
  28.  
  29. printf(w); printf("\n\n");
  30.  
  31. // Character pointers
  32.  
  33. char *p; char *pp;
  34.  
  35. // First occurrence of a word in a string
  36.  
  37. p = strstr(w, wordHi);
  38. if (p!=NULL)
  39. {
  40.  
  41. // We form a new line
  42.  
  43. *p= '\0'; strcpy(q,w); strcat(q,wordLow);
  44. *p= ' ';
  45. p= p + strlen(wordHi);
  46. pp= p;
  47.  
  48. /* Modification of the original string
  49. by deleting viewed characters */
  50.  
  51. int qq=0;
  52. while (qq<strlen(w))
  53. { w[qq]= *pp;
  54. pp++;
  55. qq++;
  56. }
  57. }
  58.  
  59. // Subsequent occurrences of a word in a string
  60.  
  61. Next: p = strstr(w, wordHi);
  62.  
  63. if (p==NULL) { strcat(q,w); goto ENDEND; } // New line created
  64.  
  65. else
  66. {
  67.  
  68. // We form a new line
  69.  
  70. *p= '\0';
  71. strcat(q,w);
  72. strcat(q,wordLow);
  73.  
  74. *p= ' ';
  75. p= p + strlen(wordHi);
  76. pp= p;
  77.  
  78. /* Modification of the original string
  79. by deleting viewed characters */
  80.  
  81. int qq=0;
  82. while (qq<strlen(w))
  83. {
  84. w[qq]= *pp;
  85. pp++;
  86. qq++;
  87. }
  88. goto Next;
  89. }
  90.  
  91.  
  92. ENDEND:
  93. printf(q); printf("\n\n"); // New line on the screen
  94.  
  95. //printf(w); printf("\n\n"); // This original line was destroyed.
  96.  
  97. printf("\n");
  98. system("pause");
  99.  
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement