Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program to find one string in another, delete the found string, and replace it with another
- #include <stdio.h>
- #include <stdbool.h>
- int main (void)
- {
- char source[81], s1[81], s2[81];
- void readLine (char buffer[]);
- void replaceString (char source[], char s1[], char s2[]);
- void printString (char source[]);
- // Enter source
- printf ("Enter the source string:n");
- readLine (source);
- // Enter string to be replaced
- printf ("Enter the string to be replaced:n");
- readLine (s1);
- // Enter string that will replace
- printf ("Enter the string that will replace the previous one:n");
- readLine (s2);
- // Replace the strings
- replaceString (source, s1, s2);
- // Print the string
- printString (source);
- return 0;
- }
- void readLine (char buffer[])
- {
- char character;
- int i = 0;
- do
- {
- character = getchar ();
- buffer[i] = character;
- i++;
- }
- while ( character != 'n' );
- buffer[i - 1] = '