Compare commits

...

2 commits

2 changed files with 22 additions and 5 deletions

View file

@ -14,7 +14,6 @@
* caractère nul.
* - La chaîne de caractère contient forcément des caractères non-nuls.
*/
/*
static char parse_digit(char *line, Node *digits_tree) {
if (isdigit(line[0])) {
return line[0];
@ -22,7 +21,6 @@ static char parse_digit(char *line, Node *digits_tree) {
return Node_stringToDigit(digits_tree, line);
}
}
*/
/**
* Lire tous les caractères d'une ligne :
@ -30,12 +28,16 @@ static char parse_digit(char *line, Node *digits_tree) {
* - Si aucun chiffre n'a é trouvé, retourner 0
*/
static char first_digit(char *line) {
while (line[0] != '\0' && !isdigit(line[0])) {
char current_digit = '\0';
Node *digits_tree = Node_new('\0');
while (line[0] != '\0' && !isdigit(current_digit)) {
current_digit = parse_digit(line, digits_tree);
line++;
}
if (*line != '\0') {
return *line;
if (current_digit != '\0') {
return current_digit;
} else {
return 0;
}
@ -45,16 +47,20 @@ unsigned int get_calibration_sum(FILE *input_file) {
unsigned int sum = 0;
char *current_line, *reversed_line;
char intermediate_buffer[3];
intermediate_buffer[2] = '\0';
while (!feof(input_file)) {
current_line = read_line(input_file);
reversed_line = strrev(current_line);
if (*current_line != '\0') {
intermediate_buffer[0] = first_digit(current_line);
intermediate_buffer[1] = first_digit(reversed_line);
sum += atoi(intermediate_buffer);
}
free(reversed_line);
free(current_line);
}

View file

@ -86,3 +86,14 @@ void Node_printTree(Node *root_node) {
print_node(root_node, 0);
putchar('\n');
}
/**
* Transformer une chaîne de caractères en un chiffre à l'aide d'un arbre
* n-aire
*/
char Node_stringToDigit(Node *root_node, char *string) {
(void) root_node;
(void) string;
return '\0';
}