Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- int main() {
- char *firstName = "";
- char *lastName = "";
- char letter[1];
- int size = 2;
- while(cin.peek() != ' ')
- {
- cin >> letter; //read next letter
- cout << "1" << endl;
- char* tempName = new char[size]; //create space for extra char and null char
- cout << "2" << endl;
- strcpy(tempName, firstName); //copy all name and add letter + null char
- cout << "3" << endl;
- strcat(tempName, letter);
- cout << "4" << endl;
- firstName = tempName; //store new version
- cout << "5" << endl;
- }
- size = 2;
- do
- {
- cin >> letter; //read next letter
- char* tempName = new char[size]; //create space for extra char and null char
- strcpy(tempName, lastName); //copy all name and add letter + null char
- strcat(tempName, letter);
- strcat(tempName, '\0');
- lastName = tempName; //store new version
- }while(cin.peek() != ' ');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement