fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. char firstName[50], lastName[50], fullName[120];
  6.  
  7. cout << "Enter first name: ";
  8. cin >> firstName;
  9.  
  10. cout << "Enter last name: ";
  11. cin >> lastName;
  12.  
  13. // Manual concatenation
  14. int i = 0, j = 0;
  15.  
  16. // Copy first name into fullName
  17. while (firstName[i] != '\0') {
  18. fullName[j] = firstName[i];
  19. i++;
  20. j++;
  21. }
  22.  
  23. // Add space
  24. fullName[j] = ' ';
  25. j++;
  26.  
  27. // Reset i for last name
  28. i = 0;
  29.  
  30. // Copy last name into fullName
  31. while (lastName[i] != '\0') {
  32. fullName[j] = lastName[i];
  33. i++;
  34. j++;
  35. }
  36.  
  37. // Null terminate the final string
  38. fullName[j] = '\0';
  39.  
  40. cout << "\nConcatenated Full Name: " << fullName << endl;
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5320KB
stdin
Dexter 
Morgan
stdout
Enter first name: Enter last name: 
Concatenated Full Name: Dexter Morgan