Commit 9df26967 by Dominik Widhalm

### Improved example solution for task 5.13

parent 7d81c93d
 ... ... @@ -16,10 +16,10 @@ /***** MACROS *****************************************************************/ // Maximum length of the input string # define STRING_MAX 80 #define STRING_MAX 80 /***** TYPEDEFS ***************************************************************/ typedef enum {FOUND, NOFOUND} search_t; /***** STRUCTURES *************************************************************/ ... ... @@ -51,14 +51,14 @@ void string_parser (char* string, int* values) { /* Numbers found index */ int numbers = 0; /* Flag if number is currently found */ int num_found = 0; search_t num_found = NOFOUND; /* Iterate over the input string */ while ((*(string+index) != '\0') && (index < STRING_MAX)) { /* Check if current character is a digit */ if ((*(string+index) >= '0') && (*(string+index) <= '9')) { /* Check if previously digits were found */ if (num_found == 1) { if (num_found == FOUND) { /* Shift left previously found number */ temp *= 10; /* Add the current digit (ASCII to number) */ ... ... @@ -67,7 +67,7 @@ void string_parser (char* string, int* values) { /* Set temp to the current digit (ASCII to number) */ temp = (int)*(string+index) - '0'; /* Set the number found flag */ num_found = 1; num_found = FOUND; } /* Check if next character is not a number */ ... ... @@ -77,7 +77,7 @@ void string_parser (char* string, int* values) { /* Increment numbers found index */ numbers++; /* Clear the number found flag */ num_found = 0; num_found = NOFOUND; } } /* Increment index */ ... ... @@ -97,8 +97,8 @@ int main (void) { /*** Local Variables ***/ /* Test string */ char string[STRING_MAX] = "183 jsb32 146 x7 hg316 h34g3k364n346 .09837"; /* Values found */ int values[STRING_MAX]; /* Values found (maximum half the number of characters) */ int values[STRING_MAX/2]; /* Counter variable */ int i = 0; ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!