Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. /* Author: Ashraf Taifour
  2. * ID: 104262768
  3. * Date: January 27th 2020
  4. * Assignment 1 */
  5.  
  6. #include <iostream>
  7. #include <iomanip> // for std::noskipws
  8.  
  9. using namespace std; //used so std:: doesn't have to be specified for every std library command ex: noskipws.
  10.  
  11. int main()
  12. {
  13. int i = 0;
  14. char str[100]; //to store any input after double quotations
  15. bool is_within_double_quotes = false;
  16. char byte;
  17. while (cin >> noskipws >> byte) //while there's user input, store user input into char byte while not skipping any whitespace
  18. {
  19. if(!is_within_double_quotes){ //initially go through this to alter this string until you encounter a "
  20. switch(byte)
  21. {
  22. case '.':
  23. byte = ' ';
  24. break;
  25. case ',':
  26. byte = ' ';
  27. break;
  28. case '?':
  29. byte = ' ';
  30. break;
  31. case '-':
  32. byte = ' ';
  33. break;
  34. case '\'':
  35. byte = ' ';
  36. break;
  37. case '\"': //once a double quotation is encountered, str will start storing the characters that will be displayed.
  38. str[i] = '\"';
  39. is_within_double_quotes = true;
  40. break;
  41. }
  42. }
  43. else if(byte == '\"'){ //if it's already in double quotations and it's about to be closed.
  44. is_within_double_quotes = false;
  45. str[i] = byte;
  46. }
  47. else //if it's within double quotes it will directly be outputted without any alterations or conditions, using str[i] so
  48. str[i] = byte;
  49.  
  50.  
  51. if(!is_within_double_quotes) //the output will use the altered byte when it isn't within double quotes
  52. cout << byte;
  53. else //when the output is within double quotes we will get the unaltered data that was stored in str
  54. cout << str[i++];
  55.  
  56.  
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement