Skip to main content
xtian
Associate III
April 8, 2013
Question

Problem including a variable

  • April 8, 2013
  • 12 replies
  • 2159 views
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.
    This topic has been closed for replies.

    12 replies

    xtian
    xtianAuthor
    Associate III
    April 8, 2013
    Posted on April 08, 2013 at 04:14

    libraries are from  olimex

    Tesla DeLorean
    Guru
    April 8, 2013
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    xtian
    xtianAuthor
    Associate III
    April 8, 2013
    Posted on April 08, 2013 at 04:21

    Hi Clive,

    thanks! I'll try that out..

    xtian
    xtianAuthor
    Associate III
    April 8, 2013
    Posted on April 08, 2013 at 10:03

    Hi Neil, Clive

    please see attachement from one of the replies

    Tesla DeLorean
    Guru
    April 8, 2013
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    xtian
    xtianAuthor
    Associate III
    April 8, 2013
    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
    Tesla DeLorean
    Guru
    April 8, 2013
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    Andrew Neil
    Super User
    April 8, 2013
    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...

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    xtian
    xtianAuthor
    Associate III
    April 9, 2013
    Posted on April 09, 2013 at 14:43

    Hi Neil, Clive1,

    Thank you very much! I still have lots to learn in C.. I'm Still MADA MADA DANE.. thank you again