Skip to content

Commit

Permalink
refactor: move validatePattern from src project to libs project
Browse files Browse the repository at this point in the history
  • Loading branch information
hozlucas28 committed Sep 11, 2024
1 parent 00ae693 commit 1ed22ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions libs/utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ int strcmpi(const char* str01, const char* str02) {
return cmp;
}

int validatePattern(char* userInput) {
char* options[] = {"glider", "toad", "press", "glider cannon"};
return isStrIn(userInput, options, 4);
}

void trimStr(char* str) {
trimLeftStr(str);
trimRightStr(str);
Expand Down
12 changes: 12 additions & 0 deletions libs/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ void printDashboardByConsole(TGame* pGame);
*/
int strcmpi(const char* str01, const char* str02);

/**
* @brief Validates the pattern of user input.
*
* This function checks if the user input matches `glider`, `toad`, `press`, or
* `glider cannon` pattern. The comparison is case insensitive.
*
* @param userInput The user input to be validated.
*
* @return 1 if the pattern is valid, 0 otherwise.
*/
int validatePattern(char* userInput);

/**
* @brief Trims leading and trailing whitespace characters from a string.
*
Expand Down
7 changes: 1 addition & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

#include "stdio.h"

int validatePattern(char* userInput) {
char* options[] = {"glider", "toad", "press", "glider cannon"};
return isStrIn(userInput, options, 4);
}

int main() {
TGame game;

Expand Down Expand Up @@ -52,4 +47,4 @@ int main() {
} while (invalidPattern);

return 0;
}
}

0 comments on commit 1ed22ab

Please sign in to comment.