diff --git a/include/p1.h b/include/p1.h index 93580d4..e01df8f 100644 --- a/include/p1.h +++ b/include/p1.h @@ -1,7 +1,8 @@ -#ifndef P1_H -#define P1_H +#ifndef P2_H +#define P2_H -int count_alphanumeric(const char* str); +void find_avg_min_max(double* arr, int size, + double* out_avg, double* out_min, double* out_max); #endif diff --git a/include/p2.h b/include/p2.h deleted file mode 100644 index e01df8f..0000000 --- a/include/p2.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef P2_H -#define P2_H - -void find_avg_min_max(double* arr, int size, - double* out_avg, double* out_min, double* out_max); - -#endif - diff --git a/include/p5.h b/include/p5.h new file mode 100644 index 0000000..93580d4 --- /dev/null +++ b/include/p5.h @@ -0,0 +1,7 @@ +#ifndef P1_H +#define P1_H + +int count_alphanumeric(const char* str); + +#endif + diff --git a/src/p1.c b/src/p1.c index 1f5c728..db581da 100644 --- a/src/p1.c +++ b/src/p1.c @@ -1,19 +1,32 @@ -#include "p1.h" +#include "p2.h" -#include - -int count_alphanumeric(const char* str) { - int num_alphanumeric = 0; - const char* current = str; - - while (*current != '\0') { - if (isalnum(*current)) { - ++num_alphanumeric; - } - - ++current; +void find_avg_min_max(double* arr, int size, + double* out_avg, double* out_min, double* out_max) { + // If there are no elements in the array, attempting to access the first + // element to initialize min and max will access memory outside the bounds + // of the array. Instead, we will return early. + if (size <= 0) { + return; } - return num_alphanumeric; + double sum = 0; + double min = arr[0]; + double max = arr[0]; + + for (int i = 0; i < size; ++i) { + sum += arr[i]; + + if (arr[i] < min) { + min = arr[i]; + } + + if (arr[i] > max) { + max = arr[i]; + } + } + + *out_avg = sum / size; + *out_min = min; + *out_max = max; } diff --git a/src/p2.c b/src/p2.c deleted file mode 100644 index db581da..0000000 --- a/src/p2.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "p2.h" - -void find_avg_min_max(double* arr, int size, - double* out_avg, double* out_min, double* out_max) { - // If there are no elements in the array, attempting to access the first - // element to initialize min and max will access memory outside the bounds - // of the array. Instead, we will return early. - if (size <= 0) { - return; - } - - double sum = 0; - double min = arr[0]; - double max = arr[0]; - - for (int i = 0; i < size; ++i) { - sum += arr[i]; - - if (arr[i] < min) { - min = arr[i]; - } - - if (arr[i] > max) { - max = arr[i]; - } - } - - *out_avg = sum / size; - *out_min = min; - *out_max = max; -} - diff --git a/src/p5.c b/src/p5.c new file mode 100644 index 0000000..1f5c728 --- /dev/null +++ b/src/p5.c @@ -0,0 +1,19 @@ +#include "p1.h" + +#include + +int count_alphanumeric(const char* str) { + int num_alphanumeric = 0; + const char* current = str; + + while (*current != '\0') { + if (isalnum(*current)) { + ++num_alphanumeric; + } + + ++current; + } + + return num_alphanumeric; +} +