cancel
Showing results for 
Search instead for 
Did you mean: 

Problem including a variable

xtian
Associate II
Posted on April 08, 2013 at 03:24

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
12 REPLIES 12
xtian
Associate II
Posted on April 08, 2013 at 04:14

libraries are from  olimex

Posted on April 08, 2013 at 04:19

Yeah, doing arithmetic on character arrays probably not a good plan, use something like strcat()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
xtian
Associate II
Posted on April 08, 2013 at 04:21

Hi Clive,

thanks! I'll try that out..

xtian
Associate II
Posted on April 08, 2013 at 10:03

Hi Neil, Clive

please see attachement from one of the replies

Posted on April 08, 2013 at 13:02

(char *)0x65 represents a string pointer at address 0x65, usually a shadow of your FLASH image, and likely containing junk characters.

char buffer[32], scratch[16];

strcpy(buffer,''this'');

strcat(buffer,''that''); // >> ''this that''

strcpy(buffer,''12345'');

strcat(buffer,''67890''); // >> ''1234567890''

strcpy(buffer,''number is '');

strcat(buffer,itoa(123, scratch, 10)); // >> ''number is 123''                                              

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
xtian
Associate II
Posted on April 08, 2013 at 18:47

Hi Clive!

Thank you very much! itoa didn;t work for me so I tried some reading anf able to come up with this....

for (int ctrStart = 0; ctrStart<4; ctrStart++)
{
char message[21], data[1];
strcpy(message,'' WILL START IN:''); //FIRST MESSAGE
snprintf(data, 10,''%d'',hsec1--); //CONVERTING VARIABLE INTO TEXT
strcat(data, '' ''); 
strcat(message,data); //COMBINING MESSAGE AND VARIABLE
SendValues (0, ''ICE KING ENTERPRISES''); //SendValues (Line number, 20 Character values);
SendValues (1, '' ''); //SendValues (Line number, 20 Character values);
SendValues (2, ''--------------------''); //SendValues (Line number, 20 Character values);
SendValues (3, buffer); //SendValues (Line number, 20 Character values);
Delay(0XFFFFF);
}

Again Thank you for you help! I've learned many things from you
Posted on April 08, 2013 at 19:00

data[1]

Seems a tad small an allocation to do the job?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 08, 2013 at 20:32

As clive1 says,

data[1]

is broken!! But why mess about with all that concatenating anyhow? Why not just do it in one go:

#define MAX_MSG_LEN 21 // Max length of a message
 char message[MAX_MSG_LEN+1]; // Size to hold a max-length message + NUL terminator
 snprintf( message, MAX_MSG_LEN, '' WILL START IN: %d '', hsec1-- );
 

Note the use of a symbolic constant rather than repeated ''Magic Numbers'' - now only one edit is required to change the maximum message length...