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.
I'm using Keil3 for arm. 1\I wanna change the string's content,eg from "2007" to "2008" 2\I wanna a pointer ,not a array,to point to the string. But when I do as follows: char *ptr = "2007"; ptr is in the flash area,so I cann't change the content of the string "2007" .
if I do like this:
char array[]="2007";//global variable char *ptr=array;
Is there any problem without the "strncpy()"function?
But ptr is superfluous, isn't it?
In what situation would you need 'ptr' that you couldn't use 'array' directly?
Sounds like you need to review the very close similarities between array names & pointers in 'C'...
c-faq.com/.../index.html
I define a struct for the button in LCD display:
typedef struct key { uint16 x; //x position in LCD uint16 y; //y position in LCD uint8 *text; //button name void (*onOK)(); //press down responsefunction struct key *next; }KEY;
and then put all the buttons in a linked-list so that I can change focus among the buttons by ptr->text. As the lengths of all the text aren't the same,I need to use pointer to save space instead of array. But sometimes I wanna change the content of ptr->text,so in the initialization I cann't do as follows: ptr->text = "2007"; //"2007" in flash I now do like this: char array[]="2007"; //"2007" in RAM ptr->text = array; //so is *(ptr->text) in RAM. All these happen because I didn't know that after the sentence:" ptr->text = "2007";",the string "2007" is in the flash.
Thank you very much!