We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi everyone can someone tell me how to declare a array of 20 characteres. I wanto to use this array to fill with a string and then display it in a LCD. Also I wanto to use a pointer to read or write in this array thanks
Store the string in code ROM:
char code str[21] ="This can be display."; LcdDisp(str);
char *LcdDisp(char *StrSrc);
Sounds like you need to get a 'C' textbook! "Store the string in code ROM" That will give a fixed string that can't be changed at runtime. Is that what you actually wanted? Note that there is no need to specify the array size when it is initialised with a string at definition:
char code str[] ="This can be display.";
If your want to read and write in an array,u can declare the array in idata or data RAM,if external RAM is valid,xdata could be used char idata/data/xdata str[21]="read and wirte here."; Note that,in C,a string ends with a '\0',if U want to store a 20-character string in a arrary,your will have to assign 21-character space for it.
char idata/data/xdata str[21]="read and wirte here.";
"to store a 20-character string in a arrary,your will have to assign 21-character space for it." But, as I said earlier, there is no need to explicitly specify the length (eg 21) in the definition - the compiler will do it automatically. In fact, unless you have a specific reason to do so, it's usually best not to specify the size - then there's no risk of miscounting, or if someone changes the string without remembering to change the size...!
but, if the length of the string which you declared is twenty,you don't need to specify the length,but while it is less than 20, for example
char idata str[]="hello";
strcpy(str,"this a 20-char sting");
"you need to store a 20-length string later on" that's why I said, "...unless you have a specific reason to do so..." In that case, yes - you would need to explicitly state the length as 21 in the definition.