The problem of parsing the input can be broken into two different problems:
Identifying consecutive series of numerical characters [0-9] or _, and identifying what those numbers are.
Code
#define LINE_SIZE <larger than your largest expected line>
char line[LINE_SIZE];
// Assuming your reading from stdin
while (fgets(line, LINE_SIZE, stdin)) {
int i;
int last_digit = 0;
// Identify digits and process
for (i = 0; i < LINE_SIZE && line[i] != '\0'; i++) {
// Check for digit [0-9]
if (isdigit(line[i])) {
// Add line[i] to the list of digits I've found
} else if (line[i] == '_') {
// Handle that I have an _
} else {
// Handle that I've reached the end of a number or _ here
}
}
}
Once you have sequences of digits there are many functions that will parse them:
sscanf("%d");
atoi(string);
Does this help clarify the solution?
This post was edited by ddevec on Feb 6 2017 07:08pm