Guest User

Untitled

a guest
Jun 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. /* Written by James Carter (ee15fay) */
  2. /* This program reads a character string input followed by a series of replacement instructions. Those instructions are then
  3. * applied to the character string */
  4. #include <stdio.h>
  5.  
  6. int main(){
  7.  
  8. int i=0, j=0, charactercount=0, charactertotal, previousinput1=1, previousinput2=0;
  9. int numberofreplacements=0, totalnumberofreplacements;
  10. /* Initialize string allocating space for up to 15 characters. Allocate 15 permutation 2 spaces for each replacement string */
  11. char string[15], replace[210], with[210], testcharacter = 'a';
  12. /* Get string and read charcters up until newline character */
  13. printf("String: ");
  14. while (testcharacter != '\n'){
  15. scanf("%c", string[charactercount]);
  16. testcharacter = string[charactercount];
  17. charactercount++;
  18. charactertotal=charactercount;
  19. }
  20. /* So long as both characters input for the replace prompt aren't the same, continue to gather replacement input */
  21. while (previousinput1 != previousinput2){
  22. printf("Replace: ");
  23. scanf("%c", replace[numberofreplacements]);
  24. scanf("%c", with[numberofreplacements]);
  25. previousinput1=replace[numberofreplacements];
  26. previousinput2=with[numberofreplacements];
  27. numberofreplacements++;
  28. totalnumberofreplacements = numberofreplacements;
  29. }
  30. /* Apply replacement input by moving through strings with incrementation */
  31. for (j=0; j<=(totalnumberofreplacements-1); j++){
  32. for (i=0; i<=(charactertotal-1); i++){
  33. if (string[i] == replace[j])
  34. string[i] = with[j];
  35. }
  36. }
  37. for (i=0; i<=(charactertotal-1); i++){
  38. /* print result */
  39. printf("%c\n", string[i]);
  40. }
  41. return 0;
  42. }
  43. ~
Add Comment
Please, Sign In to add comment