Help Needed with Strcat & Strcpy commands

eccentricbeats
eccentricbeats used Ask the Experts™
on
Below is my source code:
#include <iostream.h>
#include <string.h>

void main (void)
{
     char First [20];
     char Middle [20];
     char Last [40];
     char Full [80];

     cout << "Enter a user's first name: ";
     cin.getline(First, 20);
     cout << "Enter a user's middle name: ";
     cin.getline(Middle, 20);
     cout << "Enter a user's last name: ";
     cin.getline(Last, 20);

     strcat(Last, First);
     strcpy(Full, Last);
     strcat(Last, Middle);
     strcpy(Full, Last);
     cout << Full;
     cout << endl;
}

The problem I'm having is that I need to have a coma after the user's last name and include a space between  First and Last.  Right now if I enter a name it looks like: LastFirstMiddle, I need it to look like Last, First Middle.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try this,

#include <iostream.h>
#include <string.h>

void main (void)
{
    char First [20];
    char Middle [20];
    char Last [40];
    char Full [80];

    cout << "Enter a user's first name: ";
    cin.getline(First, 20);
    cout << "Enter a user's middle name: ";
    cin.getline(Middle, 20);
    cout << "Enter a user's last name: ";
    cin.getline(Last, 20);

    strcat(Last, ", ");
    strcpy(Full, Last);
    strcat(Last, " ");
    strcat(Last, First);
    strcpy(Full, " ");
    strcat(Full, Middle);

    cout << Full;
    cout << endl;
}
Oops, sorry.

#include <iostream.h>
#include <string.h>

void main (void)
{
   char First [20];
   char Middle [20];
   char Last [40];
   char Full [80];

   cout << "Enter a user's first name: ";
   cin.getline(First, 20);
   cout << "Enter a user's middle name: ";
   cin.getline(Middle, 20);
   cout << "Enter a user's last name: ";
   cin.getline(Last, 20);

   strcat(Last, ", ");
   strcpy(Full, Last);
   strcat(Full, " ");
   strcat(Full, First);
   strcat(Full, " ");
   strcat(Full, Middle);

   cout << Full;
   cout << endl;
}

Commented:
Since you are using C++, why not just the String library.

#include <iostream.h>
#include <String>

void main (void)
{
  String First, Middle, Last, Full;

  cout << "Enter a user's first name: ";
  cin.getline(First, 20);
  cout << "Enter a user's middle name: ";
  cin.getline(Middle, 20);
  cout << "Enter a user's last name: ";
  cin.getline(Last, 20);

  Full = Last + ", " + First + " " + Middle;
  cout << Full << endl;
}

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial