This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to declare a string

I have a list of characters and trying to put them in a string.

char line[13]; /* Line buffer */

NRF_LOG_INFO("Playlist : %c", line[0]); this works displaying 1 character at a time

NRF_LOG_INFO("Playlist : %s", line); does not work displaying the 13 character as a string

What I am needing to do is create an array that has about 1000 x string(char(13)) and be able to read it back.

none of the string functions work I assume these are more c++

Thanks

Parents
  • NRF_LOG_INFO("Playlist : %s", line); does not work displaying the 13 character as a string

     If you use the placeholder %s, it will log all the bytes from the given address until it hits a NULL character. E.g the following (the characters are written as ASCII, convert it using http://www.asciitable.com/):

    char line[4]= {0x48, 0x45, 0x59, NULL}; /* Line buffer */
    NRF_LOG_INFO("%s", line);

    Will print:

    <info> app: HEY

    If you have a NULL character in the middle of the string, it will only print the characters up to that point.

    Best regards,

    Simon

Reply
  • NRF_LOG_INFO("Playlist : %s", line); does not work displaying the 13 character as a string

     If you use the placeholder %s, it will log all the bytes from the given address until it hits a NULL character. E.g the following (the characters are written as ASCII, convert it using http://www.asciitable.com/):

    char line[4]= {0x48, 0x45, 0x59, NULL}; /* Line buffer */
    NRF_LOG_INFO("%s", line);

    Will print:

    <info> app: HEY

    If you have a NULL character in the middle of the string, it will only print the characters up to that point.

    Best regards,

    Simon

Children
Related