Friday, August 19, 2011

some sscanf magic

In the world of regular expressions and comprehensive frameworks like boost, ace etc it is justifiable if you have forgotten about poor sscan and the string parsing capabilities it provides.

Recently I had to do some rudimentary string parsing in C and didn't have external frameworks at my disposal. Thus sscanf came to the rescue and solved the problem just one line.

The following invocation of sscanf extracts from str everything uptill the first '*' and puts it in res_str.

sscanf(str, "%[^*]%*s", res_str);

No comments: