1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
const char *p = "TAGNAME_C123_V45_S67_M89";
const char *q = "EMA_NGAT_C111_V22_S33_M44";
int c, v, s, m;
if(sscanf(p, "%*[^_]_C%d_V%d_S%d_M%d", &c, &v, &s, &m) == 4)
printf("C=%d\nV=%d\nS=%d\nM=%d\n", c, v, s, m);
else
printf("This is not a right format");
if(sscanf(q, "%*[^_]_C%d_V%d_S%d_M%d", &c, &v, &s, &m) == 4)
printf("C=%d\nV=%d\nS=%d\nM=%d\n", c, v, s, m);
else
printf("This is not a right format");
|