How to set the width of the format specifier for a variable type char array in C? -
i have function --
bool datapersistence::persistuidetails (const char *data, quint32 len) { tlog_func_enter(); bool retval = true; char tmp[len+1]; strncpy (tmp, data, len); //working on persisting ui details. char type[len]; char uivers[len]; char mwvers[len]; char ts[len]; sscanf (tmp, "%s %s %s %s", type, uivers, mwvers, ts); }
i want put maximum width format specifier. how can in c?
something %255s
use sprintf print format string:
char formatstring[256]; sprintf(formatstring, "%%%ds %%%ds %%%ds %%%ds", len, len, len, len);
then use in sscanf:
sscanf (tmp, formatstring, type, uivers, mwvers, ts);
Comments
Post a Comment