I have two arrays of char: a,b. How can i create with a loop "for" the new array vet, which is the union of the two alternating array a, b?
#include <stdio.h>
int main(void) {
char a[] = "BNSIO";
char b[] = "EISM\a";
char vet[sizeof(a) + sizeof(b)];
for (int i = 0; i < (sizeof(a) + sizeof(b)); i++) {
}
for (int i = 0; i < (sizeof(a) + sizeof(b)); i++){
printf("%c", vet[i]);
}
}
For alternating values from both arrays, try this (assuming lengths are equal):
int main()
{
int i;
char a[] = "BNSIO";
char b[] = "EISM\a";
char vet[sizeof(a) + sizeof(b)];
for( i = 0; i < sizeof(a); i++) {
vet[2*i] = a[i];
vet[2*i+1] = b[i];
}
for(i = 0; i < sizeof(vet) ; i++){
printf("%c", vet[i]);
}
}