How to combined two array please?

Hi,
I have an array1[NameOne], and array2[SitA1], how to get array3[NameOneSitA1] need help please.
Thanks
adam

An array of struct type, where the struct contains NameOne and SitA1.

Guessing in the absence of information about what you're doing... :slight_smile: ... as concatenating variable names never works...

I remember from your previous posts, your English is not very good. So, you need to take a lot more time to explain yourself.

1 Like

Thanks.
Yes, my English is no good.

sorry. it is not about array.
it is about char Name[NameOne]; char Sit[SitA1]; char plan[NameOneSitA1]

What kind of concatenation? Serial? Interleaved? You see my problem?

1 Like

Please provide a small example of what array1, array2, and array3 should look like.

2 Likes

...and it wouldn't hurt to explain why you need to do this...

1 Like

Sorry.
it is nothing hurt, I guess any other way may make things more unclear?

Yes there is, reply #5. Examples help a lot to overcome language issues.

see if this better:

char name1[7] ;
char sit[5] ;
char plan[12];

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
plan = (name1[], sit[]);
Serial.print("plan=");
Serial.print(plan);

}

Oh, strcat()
https://www.tutorialspoint.com/c_standard_library/c_function_strcat.htm

Thanks.
this code from your link doesn't print out result:

#include <stdio.h>
#include <string.h>

int main () {
   char src[50], dest[50];

   strcpy(src,  "This is source");
   strcpy(dest, "This is destination");

   strcat(dest, src);

   printf("Final destination string : |%s|", dest);
   //Serial.print(Final destination string);
   return(0);
}

NOR:

#include <stdio.h>

#include <string.h>

#include <stdio.h>

#include <string.h>

 

#define SIZE 40

  

int main(void)

{

  char buffer1[SIZE] = "computer";

  char * ptr;

 

  ptr = strcat( buffer1, " program" );

  printf( "buffer1 = %s\n", buffer1 );

  Serial.print(buffer1);
}

Something to do with using main() instead of setup()/loop(), maybe?

What happens when main() terminates and exits? There may be data left in the serial transmit buffer when that happens.

Try ending main() with 'while(1)' to prevent that.

@shanren The first program in #11 above functions perfectly if…

If you run it where it is meant to be run. Clearly it is not an example Arduino sketch.

Try it here

or on your own computer with the command line and your C compiler.

The key functions are available on the Arduino and can be used identically.

a7

1 Like

Great!
Thank you.
I put it : New Arduino Uno Project - Wokwi Simulator so....

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.