Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Author: Ashraf Taifour
- * ID: 104262768
- * Date: January 27th 2020
- * Assignment 1 */
- #include <iostream>
- #include <iomanip> // for std::noskipws
- using namespace std; //used so std:: doesn't have to be specified for every std library command ex: noskipws.
- int main()
- {
- int i = 0;
- char str[100]; //to store any input after double quotations
- bool is_within_double_quotes = false;
- char byte;
- while (cin >> noskipws >> byte) //while there's user input, store user input into char byte while not skipping any whitespace
- {
- if(!is_within_double_quotes){ //initially go through this to alter this string until you encounter a "
- switch(byte)
- {
- case '.':
- byte = ' ';
- break;
- case ',':
- byte = ' ';
- break;
- case '?':
- byte = ' ';
- break;
- case '-':
- byte = ' ';
- break;
- case '\'':
- byte = ' ';
- break;
- case '\"': //once a double quotation is encountered, str will start storing the characters that will be displayed.
- str[i] = '\"';
- is_within_double_quotes = true;
- break;
- }
- }
- else if(byte == '\"'){ //if it's already in double quotations and it's about to be closed.
- is_within_double_quotes = false;
- str[i] = byte;
- }
- else //if it's within double quotes it will directly be outputted without any alterations or conditions, using str[i] so
- str[i] = byte;
- if(!is_within_double_quotes) //the output will use the altered byte when it isn't within double quotes
- cout << byte;
- else //when the output is within double quotes we will get the unaltered data that was stored in str
- cout << str[i++];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement