Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void concatStrings(char target[], const char source[]){
- int targetIndex = 0;
- while(target[targetIndex]){ /// while it's not the "\0" continue the loop,
- /// otherwise break
- targetIndex++;
- }
- int sourceIndex = 0;
- while(source[sourceIndex]){
- target[targetIndex] = source[sourceIndex];
- targetIndex++;
- sourceIndex++;
- }
- target[targetIndex] = '\0';
- cout << "Size of target : " << targetIndex << endl;
- cout << "Size of source : " << sourceIndex << endl;
- }
- int main(){
- char string1[256];
- cin.getline(string1,128);
- char string2[128];
- cin.getline(string2, 128);
- concatStrings(string1, "-");
- concatStrings(string1,string2);
- cout << "\n" << string1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement