Go Down

Topic: Change some char in char array (Read 87 times) previous topic - next topic

Brkic

Hi everybady,

i have problem with some code

char ONE[1];
char MENU[][maxItemSize] ={"Date","Time","Alarm","Format","Zone","Daylight","BACK"};
.
..
...

strcpy(ONE,"Proba");

I want change MENU[1] with ONE //MENU[1]=Time and i want MENU[1]=Proba

///

when ONE is string i will use ONE.toCharArray(MENU[2], ONE.length()+1); and everything is work but with ONE=char i dont know.

Somebody can help me, thanks.


UKHeliBob

Code: [Select]
char ONE[1];
How many characters can this array hold ?


Code: [Select]
strcpy(ONE,"Proba");
How many characters are you copying to it ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Brkic

#2
Oct 13, 2019, 10:48 pm Last Edit: Oct 13, 2019, 10:54 pm by Brkic
ONE have One character

strcpy(ONE,"P");  // this is only example "P" or "Proba"

Delta_G

#3
Oct 13, 2019, 10:52 pm Last Edit: Oct 13, 2019, 10:54 pm by Delta_G
ONE have One character

strcpy(ONE,"P");  // this is only example "P" or "Proba"
Even "P" is actually 2 characters.  It's the 'P' and also the null terminator '\0'

You need ONE to have the same number of characters as the second dimension of MENU.  So use MaxItemSize there.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Brkic

OK, I will change that

char ONE[2];
char MENU[][maxItemSize] ={"Date","Time","Alarm","Format","Zone","Daylight","BACK"};
.
..
...

strcpy(ONE,"P");

I want change MENU[1] with ONE //MENU[1]=Time and i want MENU[1]=P

Delta_G

#5
Oct 13, 2019, 11:00 pm Last Edit: Oct 13, 2019, 11:01 pm by Delta_G
I want change MENU[1] with ONE //MENU[1]=Time and i want MENU[1]=P
I don't understand what you mean by this.

Maybe:
Code: [Select]

strcpy(MENU[1], "P");


or
Code: [Select]

strcpy(MENU[1], ONE);


|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Brkic

This is a code when ONE is string

char MENU[][maxItemSize] ={"Date","Time","Alarm","Format","Zone","Daylight","BACK"};
String ONE;

void niz()
  {
    ONE="Proba";
    ONE.toCharArray(menu[1], amp.length()+1);
  }

and that code is work OK,

now ONE is char,how to replace value in a MENU

char ONE[6];

Brkic

#7
Oct 13, 2019, 11:14 pm Last Edit: Oct 13, 2019, 11:14 pm by Brkic
Thanks it worked !! :-)

Code: [Select]

strcpy(MENU[1], ONE);




Delta_G

Thanks it worked !! :-)

Code: [Select]

strcpy(MENU[1], ONE);




Yeah, it's the same as this one that you were already using:

Code: [Select]
strcpy(ONE,"P");


I guess that's why it was confusing.  You seemed to already understand the answer. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up