sprintf in C (pointer to an array of char elements) -
i newbie in c, , want like
uint8_t message[12]; message[0] = 0x00; message[1] = 0x00; message[2] = 0x00; message[3] = 0x00; message[4] = 0x00; message[5] = 0x00; message[6] = 0x00; message[7] = 0x00; message[8] = 0x00; message[9] = 0x00; message[10] = 0x00; message[11] = 0x00; sprintf(_smess,"at$ss=%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", message[0], message[1], message[2], message[3], message[4], message[5], message[6], message[7], message[8], message[9], message[10], message[11]);
but don't know how declare variable _smess, i've tried char *_smess or uint8_t _smess[12] got error anyway
if declare char _smess[43];
got error:
multiple markers @ line - incompatible implicit declaration of built-in function 'sprintf' [enabled default] - implicit declaration of function 'sprintf' [-wimplicit-function-declaration] - each undeclared identifier reported once each function appears in - '_smess' undeclared (first use in function)
you know how big string based on format string passed sprintf
(i.e. 42 characters), declare char array of @ least size, making sure leave room nul ('\0'
) terminator:
char _smess[43];
edit:
the error "incompatible implicit declaration of built-in function 'sprintf'" because didn't #include <stdio.h>
@ top of file.
the "'_smess' undeclared" error because didn't define before used. needs appear before sprintf
call.
Comments
Post a Comment