View previous topic :: View next topic |
Author |
Message |
bright_krom
Joined: 11 May 2010 Posts: 3
|
Char[] Array Problem |
Posted: Tue May 11, 2010 3:57 pm |
|
|
Hi everyone,
I wanna ask something;
Code: | char *x;
x="Hello"; | or Code: | char x[10];
x="Hello"; |
These codes are not loading a string to x, how can I do? Help please.
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue May 11, 2010 4:01 pm |
|
|
char x[5] = {'h','e','l','l','o'};
.... if i remember right.. that should do it....
Gabriel. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 11, 2010 4:33 pm |
|
|
You can initialize it when you declare the array. Example:
Code: | char x[6] = "Hello"; |
Or, you can load the array at runtime, by using strcpy:
Code: |
char x[6];
strcpy(x, "Hello");
|
|
|
![](templates/subSilver/images/spacer.gif) |
bright_krom
Joined: 11 May 2010 Posts: 3
|
|
Posted: Wed May 12, 2010 5:00 am |
|
|
Thank you Gabriel and PCM. |
|
![](templates/subSilver/images/spacer.gif) |
|