Compare commits
No commits in common. "31dcab585339a70a62ee0e1934fb12811d065c8e" and "afb38673ea9f5c45e7c3e8701eb7e44ca66eed6a" have entirely different histories.
31dcab5853
...
afb38673ea
2 changed files with 5 additions and 22 deletions
|
@ -14,6 +14,7 @@
|
||||||
* caractère nul.
|
* caractère nul.
|
||||||
* - La chaîne de caractère contient forcément des caractères non-nuls.
|
* - La chaîne de caractère contient forcément des caractères non-nuls.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
static char parse_digit(char *line, Node *digits_tree) {
|
static char parse_digit(char *line, Node *digits_tree) {
|
||||||
if (isdigit(line[0])) {
|
if (isdigit(line[0])) {
|
||||||
return line[0];
|
return line[0];
|
||||||
|
@ -21,6 +22,7 @@ static char parse_digit(char *line, Node *digits_tree) {
|
||||||
return Node_stringToDigit(digits_tree, line);
|
return Node_stringToDigit(digits_tree, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lire tous les caractères d'une ligne :
|
* Lire tous les caractères d'une ligne :
|
||||||
|
@ -28,16 +30,12 @@ static char parse_digit(char *line, Node *digits_tree) {
|
||||||
* - Si aucun chiffre n'a été trouvé, retourner 0
|
* - Si aucun chiffre n'a été trouvé, retourner 0
|
||||||
*/
|
*/
|
||||||
static char first_digit(char *line) {
|
static char first_digit(char *line) {
|
||||||
char current_digit = '\0';
|
while (line[0] != '\0' && !isdigit(line[0])) {
|
||||||
Node *digits_tree = Node_new('\0');
|
|
||||||
|
|
||||||
while (line[0] != '\0' && !isdigit(current_digit)) {
|
|
||||||
current_digit = parse_digit(line, digits_tree);
|
|
||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_digit != '\0') {
|
if (*line != '\0') {
|
||||||
return current_digit;
|
return *line;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -47,20 +45,16 @@ unsigned int get_calibration_sum(FILE *input_file) {
|
||||||
unsigned int sum = 0;
|
unsigned int sum = 0;
|
||||||
char *current_line, *reversed_line;
|
char *current_line, *reversed_line;
|
||||||
char intermediate_buffer[3];
|
char intermediate_buffer[3];
|
||||||
|
|
||||||
intermediate_buffer[2] = '\0';
|
intermediate_buffer[2] = '\0';
|
||||||
|
|
||||||
while (!feof(input_file)) {
|
while (!feof(input_file)) {
|
||||||
current_line = read_line(input_file);
|
current_line = read_line(input_file);
|
||||||
reversed_line = strrev(current_line);
|
reversed_line = strrev(current_line);
|
||||||
|
|
||||||
if (*current_line != '\0') {
|
if (*current_line != '\0') {
|
||||||
intermediate_buffer[0] = first_digit(current_line);
|
intermediate_buffer[0] = first_digit(current_line);
|
||||||
intermediate_buffer[1] = first_digit(reversed_line);
|
intermediate_buffer[1] = first_digit(reversed_line);
|
||||||
|
|
||||||
sum += atoi(intermediate_buffer);
|
sum += atoi(intermediate_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(reversed_line);
|
free(reversed_line);
|
||||||
free(current_line);
|
free(current_line);
|
||||||
}
|
}
|
||||||
|
|
11
src/node.c
11
src/node.c
|
@ -86,14 +86,3 @@ void Node_printTree(Node *root_node) {
|
||||||
print_node(root_node, 0);
|
print_node(root_node, 0);
|
||||||
putchar('\n');
|
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';
|
|
||||||
}
|
|
||||||
|
|
Reference in a new issue