How to write into an objet

Good evening,

I am trying to give a value to an objet wihtout success.

I declare it like this:

 struct MyFix {
 //float field1;
   //byte field2;
   char position[FIXSIZE];

Then I create an object

MyFix obj;

But now I would like to give a value to position

char str[]="totototo";
obj.position = str;

Then I print it

Serial.println(fix.position); and it should pirnt:


My problem is here

obj.position = str;

it does not work and I also tried


Which is the good way to attribute a value to an object?

Arrays can't copy themselves:

You could use strncpy

char str[]="totototo";

strncpy(obj.position, str, FIXSIZE);


Thank, yes, it what I just found

I did like this


But what's the difference between memset and strcpy

I think strcpy() does not add a \0 and the end

I think strcpy() does not add a \0 and the end

You think wrong. The main difference between memcpy() and strcpy() is that strcpy() figures out how much data to copy. You have to tell memcpy().

Thank for this :)