Hey guys I need to copy multiple string arrays into one array to use to display output. I need to copy the name, addr, telephone, carinfo, payment array to the output array. How would I go about doing that.

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

void dissectCustLine( char *, char *, char *, char *, char *, char * );
void fixName( char * );
void fixAddress( char * );
void fixPhone ( char * );


int main()
{
    ifstream inFile;
    char input[80];
    char name[15];
    char addr[18];
    char telephone[12];
    char carinfo[21];
    char payment[16];
    char output[80];
    
    inFile.open( "custfile.txt" );
    
    if ( inFile.fail() )
       {
       cout << "input file did not open";
       exit(0);
       }
    inFile.getline( input, 80 );
    while ( inFile )
    {
    dissectCustLine( input, name, addr, telephone, carinfo, payment );
    fixName( name );
    fixAddress ( addr );
    fixPhone ( telephone );
    cout << addr << endl;
    
    inFile.getline( input, 80 );
    }     
    system ("pause");
    return 0;
}
/*********************************************************/
void dissectCustLine ( char *i, char *n, char *a, char *t, char *c, char *p )
{
    strncpy(n, i, 15);
    n[15] = '\0';
    
    strncpy(a, i+15, 18);
    a[18] = '\0';
    
    strncpy(t, i+33, 12);
    t[12] = '\0';
    
    strncpy(c, i+45, 21);
    c[21] = '\0';
    
    strncpy(p, i+67, 8);
    p[8] = '\0';
}
/*********************************************************/
void fixName ( char *n )
{
     char temp[80];
     char *spacePtr;
     spacePtr = strchr(n, ',');
     if ( spacePtr != 0 )
     {
     strcpy(temp,spacePtr+1);
     strcat(temp, ",");
     *spacePtr = '\0';
     strcat(temp, n);
     strcpy(n, temp);
     }
}
/******************************************/
void fixAddress ( char *a )
{
      while(*a != NULL)
      {
      if(isalpha(*a)) break;
      a++;
      }
      *a = toupper(*a);
      a++;
      
      while(*a != NULL)
      {
      *a = tolower(*a);
      a++; 
      }
      a++;
}
/********************************************************/
void fixPhone ( char *t)
{
     
}

>>I need to copy the name, addr, telephone, carinfo, payment array to the output array. How would I go about doing that

use strcat() to concantinate c-style character arrays. You just need to make sure the destination string is big enough to hold all the strings you want to put into it.

char destination[255] = {0};
strcpy(destination "Hello ");
strcat(destination, "World");

Would it just be done like this

strcpy(output[80],name[15])
strcpy(output[80],addr[18])

and so on?

>>Would it just be done like this
No. See my previous example

strcpy(output,name) // strcpy() only for the first one
strcat(output,addr); // strcat() for all the others
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.