hi I have a 2d array that I want to set each element to a char array. how would I go about doing that.
char bdaylist[50][6];
this is my 2d array
my char array I'm trying to set each element to is
char charBuf[13];
in the charBuf variable has a string that is no more then 13 chars long and I convert it to a char array. then set it with this
bdaylist[row][col] = charBuf;
I don't know why I'm not getting the correct output in the 2d array all I get is � and blank chars can anyone help me.
Doesn't IDE give you an error or at least a warning at this point?
The left side of this expression is of type char, the right side is a pointer to char.
Assigning one to the other will not do anything good
I’m reading this on my mobile and if I click on the link I get a prompt to download the file, could you please tell me why should I download your .ino file on my mobile?
you can't,
because bdaylist[0][1] is a single char and charBuf is a string up to 12 chars long
You should first calculate the pointer offset of the starting position where the contains of the charBuf should be copied and than use this pointer as destination parameter in strcpy()
Use strncpy or strlcpy if you want to pass the size (better us the size of the destination to not overflow (mind the null)
you would need to take the address of index bdaylist[0][0]
You can just use the first part to get the address
strcpy(bdaylist[0], charBuf); // MAKE SURE THERE IS ENOUGH ROOM
It is true if you want to insert the buffer starting from first (zero-numbered) position of array row bdaylist[0][0]
But if I need to insert it from position bdaylist[0][1], as OP said - the only way that I see to do that will be follows:
i guess you are right it is a 3d array each row has up to 6 elements and each Column has 50 sets of 6 rows and each element has up to 13 chars in it.
can you help me with my error I'm been trying strncpy but I have to shorten my 3d array to bdaylist[2][6][13];. I need to store more then 2 columns of info.
This is an illustration of why it is necessary to correctly describe the task and always show the full code.
You confused yourself and others and they wasted time on you
Good luck