title: c++ c-strings, strncat, strncpy
body: <p>This program is supposed to input someones name and output it like " Last, first middle". The names are supposed to be stored in 3 different arrays and their is a fourth array for the full name at the end. I am also supposed to use strncpy and strncat to build the fourth array. My issue im having is i dont know what the use of strncpy would be in this situation and how to use it. I can make the program say "first middle last" but not the correct output. Another issue im having is the while loop is supposed to allow the user to say 'q' or 'Q' and quit the program but it doesnt do this   </p>
  
  <pre><code>#include &lt;iomanip&gt;
  #include &lt;iostream&gt;
  #include &lt;cctype&gt;
  using namespace std; 
  
  int main()
  {
  char replay; //To hold Q for quit
  
  const int SIZE = 51;
  char firstName[SIZE]; // To hole first name
  char middleName[SIZE]; // To hold middle name
  char lastName[SIZE]; // To hold last name
  char fullName[SIZE]; //To hold the full name
  int count = 0;
  int maxChars1;
  int maxChars2;
  
  
  
  cout &lt;&lt; "Enter Q to quit or enter your first name of no more than " &lt;&lt; (SIZE - 1)
       &lt;&lt; " letters: ";
  cin.getline(firstName, SIZE);
  
  while(firstName[SIZE] != 'Q' || firstName[SIZE] != 'q')
  {
  cout &lt;&lt; "\nEnter your middle name of no more than " &lt;&lt; (SIZE - 1)
       &lt;&lt; " letters: ";
  cin.getline(middleName, SIZE);
  
  cout &lt;&lt; "\nEnter your last name of no more than " &lt;&lt; (SIZE - 1)
       &lt;&lt; " letters: ";
  cin.getline(lastName, SIZE);
  
  maxChars1 = sizeof(firstName) - (strlen(firstName) + 1);
  strncat(firstName, middleName, maxChars1);
  
  cout &lt;&lt; firstName &lt;&lt; endl;
  
  maxChars2 = sizeof(lastName) - 1;
  strncpy(firstName, lastName, maxChars2);
  lastName[maxChars2] = '\0';
  
  cout &lt;&lt; lastName &lt;&lt; endl;
      }
  
  system("pause");
  return 0;
  }
  </code></pre>