String concatenation, connect "acegikm" and "BDFHJLNPQ"
code
# include & lt; Stdio. H>
20 # define N
Char arr [N]={0};
Void main ()
{
Char a []="acegikm";
Char [b]="BDFHJNPQ";
int i=0;
for(i=0; i <7. I++)
Arr=[I] a [I];
for(i=0; i <9. I++)
Arr [I + 7] [I]=b;
for(i=0; iPrintf (" % c \ n ", arr [I]);
}
Results the
The arithmetic idea for the
If you want to any string to connect, can use a two-dimensional array of target string, then two-dimensional arrays into one array is implemented any string concatenation
code
//connection
Void Connect (char [M] [N], a char * b)
{
int i,j;
int k=0;
//will be a [M] [N] elements, in turn, assign a value to the array b
for(i=0; ifor(j=0; A [I] [j].='\ 0'; J++)
B=[k++] a [I] [j];//use Pointers for * (* (a + I) + j)
B [k]='\ 0';
}
CodePudding user response:
# include & lt; Stdio. H>
20 # define N
Char arr [N]={0};
Int main ()
{
Char a []="acegikm";
Char [b]="BDFHJNPQ";
int i=0;
for(i=0; iArr=[I] a [I];
for(i=0; iArr [I + 7] [I]=b;
# if 0
for(i=0; iPrintf (" % c \ n ", arr [I]);
# the else
Puts (arr);
# endif
}
For your reference ~
CodePudding user response:
char ch;
int i=0;
Cha r * p=a;
While (ch=* p++)
Arr [i++]=ch;
P=b;
While (ch=* p++)
Arr [i++]=ch;
Arr [I]='\ 0';