Advertisement
Cinestra

Concatenate

Jan 12th, 2023
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. void concatenate(char first_string[], char second_string[])
  6. {
  7.     int end_of_first_string = strlen(first_string);
  8.  
  9.     for (int i = 0; i < strlen(second_string); i++)
  10.     {
  11.         int j = end_of_first_string + i;
  12.         first_string[j] = second_string[i];
  13.     }
  14.  
  15.     first_string[strlen(first_string)] += 0;
  16. }
  17.  
  18. int main()
  19. {
  20.     char firstname[20] = "YoonA";
  21.     char lastname[20] = "Lim";
  22.  
  23.     char desiredname[20];
  24.     strcpy_s(desiredname, firstname);
  25.  
  26.     cout << "Hi " << desiredname << endl;
  27.     cout << "YoonA has " << strlen(desiredname) << " letters in it" << endl;
  28.  
  29.     concatenate(firstname, lastname);
  30.     cout << firstname;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement