Browse Source

Added operation handler formatting check

remotes/origin/develop
Eric Bagus 11 months ago
parent
commit
e57f0309a4
  1. 26
      src/operationHandler.c
  2. 2
      src/operationHandler.h

26
src/operationHandler.c

@ -1,5 +1,7 @@
#include "operationHandler.h"
#include <stdbool.h>
#include <ctype.h>
#include <stdlib.h>
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);
}

2
src/operationHandler.h

@ -4,4 +4,6 @@
bool checkOperationInput(int);
bool containsTwoNumbers(const char*);
#endif //THEADMIRALS_OPERATIONHANDLER_H
Loading…
Cancel
Save