I'm currently working through the book "C Programming: A Modern Approach" (by K.N.King) and I'm having some problems with the following exercise:
My solution isAssume that "str" is a string that contains a "sales rank" immediately preceded by the # symbol (other characters may precede the # and/or follow the sales rank). A sales rank is a series of decimal digits possibly containing commas, such as the following examples:
989
24,675
1,162,620
Write a call of "sscanf" that extracts the sales rank (but not the # symbol) and stores it in a string variable named "sales_rank".
which works except for the case where "str" starts with the # symbol (without any characters preceding it).Code:sscanf(str, "%*[^#]#%[0-9,]", sales_rank);
After rereading the corresponding parts in the book and of the man page of sscanf I don't see any way to have a single call of sscanf so that it works both for any characters before # and no character before #.
Am I missing something or misinterpreting the exercise?
Bye, Andreas