CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

define an array of constants including the character (,)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

define an array of constants including the character (,)
PostPosted: Tue Nov 26, 2013 11:27 am     Reply with quote

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
                  };
Ttelmah



Joined: 11 Mar 2010
Posts: 19516

View user's profile Send private message

PostPosted: Tue Nov 26, 2013 1:15 pm     Reply with quote

You can include any character, by using it's octal or hex value,
So \x2C or \053 generates a comma.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 26, 2013 1:17 pm     Reply with quote

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:
Quote:
CGREG:1,1


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.
Ttelmah



Joined: 11 Mar 2010
Posts: 19516

View user's profile Send private message

PostPosted: Tue Nov 26, 2013 1:51 pm     Reply with quote

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
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Tue Nov 26, 2013 7:14 pm     Reply with quote

Ok, Thank you..
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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