Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Written by James Carter (ee15fay) */
- /* This program reads a character string input followed by a series of replacement instructions. Those instructions are then
- * applied to the character string */
- #include <stdio.h>
- int main(){
- int i=0, j=0, charactercount=0, charactertotal, previousinput1=1, previousinput2=0;
- int numberofreplacements=0, totalnumberofreplacements;
- /* Initialize string allocating space for up to 15 characters. Allocate 15 permutation 2 spaces for each replacement string */
- char string[15], replace[210], with[210], testcharacter = 'a';
- /* Get string and read charcters up until newline character */
- printf("String: ");
- while (testcharacter != '\n'){
- scanf("%c", string[charactercount]);
- testcharacter = string[charactercount];
- charactercount++;
- charactertotal=charactercount;
- }
- /* So long as both characters input for the replace prompt aren't the same, continue to gather replacement input */
- while (previousinput1 != previousinput2){
- printf("Replace: ");
- scanf("%c", replace[numberofreplacements]);
- scanf("%c", with[numberofreplacements]);
- previousinput1=replace[numberofreplacements];
- previousinput2=with[numberofreplacements];
- numberofreplacements++;
- totalnumberofreplacements = numberofreplacements;
- }
- /* Apply replacement input by moving through strings with incrementation */
- for (j=0; j<=(totalnumberofreplacements-1); j++){
- for (i=0; i<=(charactertotal-1); i++){
- if (string[i] == replace[j])
- string[i] = with[j];
- }
- }
- for (i=0; i<=(charactertotal-1); i++){
- /* print result */
- printf("%c\n", string[i]);
- }
- return 0;
- }
- ~
Add Comment
Please, Sign In to add comment