Imagine the following:
you read in a line with scanf() , but you only need some of the data in a line.
Is there an easy way to throw away extraneous information without losing the ability to check if there is relevant data so that you can easily discard invalid rows?
Example:
const char* store = "Get: 15 beer 30 coke\n"; const char* dealer= "Get: 8 heroine 5 coke\n"; const char* scream= "Get: f* beer 10 coke\n";
I want to take the first string, but forget about beer, because beer is yuckie. I want to reject the second and third lines because they obviously do not match the lists for 7/11;
So, I was thinking about the following construction:
char* bId = new char[16]; char* cId = new char[16]; int cokes; sscanf([string here], "Get: %d %s %d %s\n", [don't care], bId, &cokes, cId);
That way, I would keep the format check, but what would I set for [it doesn't matter] that doesn't make the compiler whine?
Of course, I could just make a variable that I will not use later, but this is not a question of this question. Also checking the left and right sides separately is an obvious solution that I am not looking for here.
So, is there a way to not care, but still check the line type in scanf and friends?
c ++ c scanf
Nomen
source share