【原创】连接字符串数组

#include  < stdio.h >
#include 
< stdlib.h >

char *  UnionStringArray( char *  StringArr[], int  iArrCount, char *  strTarget);

int  main( int  argc,  char   * argv[])
{
  
char *  billFields[ 11 =  { " product_id " , " product_class_id " , " product_name " , " product_unit " , " product_num " , " product_pym " ,
                          
" product_provider " , " purchase_date " , " remark " , " rec_status " , " operator " };

  
char  select_fields[ 1000 ] = "" ;
  
  UnionStringArray(billFields,
11 ,select_fields);
  printf(
" %s\r\n " ,select_fields);    
                  
  system(
" PAUSE " );    
  
return   0 ;
}

char *  UnionStringArray( char *  StringArr[], int  iArrCount, char *  strTarget)
{
   
int  i;
   
for (i = 0 ;i < iArrCount;i ++ )
   {
      
if (i < iArrCount - 1 )
      {
        strcat(strTarget,
" t1. " );
        strcat(strTarget,StringArr[i]);
        strcat(strTarget,
" , " );
      }
      
else
      {
        strcat(strTarget,
" t1. " );
        strcat(strTarget,StringArr[i]);
      }
   }
   
   
return  strTarget;              
}

 

该程序的测试环境:

WinXPSP2,Dev C++ 4.9.9.2

 

你可能感兴趣的:(字符串)