![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
define an array of constants including the character (,) |
Posted: Tue Nov 26, 2013 11:27 am |
|
|
Hello, I want to define an array of constants including the character (,) but does not allow me to do so, is there any way to define this ("CGREG 1.1)?
Code: | const char Strings[TOTAL_STRINGS][SIZE_COMMAND]={"OK\0", // index 0
"CGREG:1,1\0", // index 1
"+CMTI\0", // index 2
"ERROR\0", // index 3
}; |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Tue Nov 26, 2013 1:15 pm |
|
|
You can include any character, by using it's octal or hex value,
So \x2C or \053 generates a comma.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 26, 2013 1:17 pm |
|
|
It works for me. I compiled the program shown below in vs. 5.016 and
ran it in MPLAB simulator, and I got the following output. It displays the comma:
Here is the test program:
Code: |
#include <18F4520.h>
#fuses INTRC_IO, BROWNOUT, PUT, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
#define TOTAL_STRINGS 4
#define SIZE_COMMAND 11
const char Strings[TOTAL_STRINGS][SIZE_COMMAND]=
{"OK\0", // index 0
"CGREG:1,1\0", // index 1
"+CMTI\0", // index 2
"ERROR\0", // index 3
};
//===================================
void main()
{
printf(Strings[1]);
while(1);
} |
Note that the compiler automatically puts a 0x00 byte at the end of each
string (this is part of the definition of a string). You are adding an extra
0x00 on the end of each string, for some unknown reason. So you really
have two zeros at the end of each string. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Tue Nov 26, 2013 1:51 pm |
|
|
I wonder if he is running out of space?.
Doesn't show the declaration for 'SIZE_COMMAND', and with the extra terminators, would need 11 characters for this line.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Tue Nov 26, 2013 7:14 pm |
|
|
Ok, Thank you.. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|