diff --git a/src/operationHandler.c b/src/operationHandler.c index 0f63fb7..ef41efb 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -1,5 +1,7 @@ #include "operationHandler.h" #include +#include +#include bool checkOperationInput(int input) { switch (input) { @@ -7,4 +9,28 @@ bool checkOperationInput(int input) { return true; } return false; +} + +bool containsTwoNumbers(const char* str) { + int numbersCount = 0; + bool hasSpace = false; + bool isInNumber = false; + + for (int i = 0; str[i] != '\0'; i++) { + if (isdigit(str[i])) { + if (!isInNumber) { + isInNumber = true; + numbersCount++; + } + } else if (str[i] == ' ' && isInNumber) { + hasSpace = true; + isInNumber = false; + } else if (str[i] == ' ' && !isInNumber) { + hasSpace = false; + } else { + hasSpace = false; + isInNumber = false; + } + } + return (numbersCount == 2 && hasSpace); } \ No newline at end of file diff --git a/src/operationHandler.h b/src/operationHandler.h index 5293b1e..cb083e2 100644 --- a/src/operationHandler.h +++ b/src/operationHandler.h @@ -4,4 +4,6 @@ bool checkOperationInput(int); +bool containsTwoNumbers(const char*); + #endif //THEADMIRALS_OPERATIONHANDLER_H