Skip to content

Commit

Permalink
Definition of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoGiannotti committed Sep 10, 2024
1 parent f7ed215 commit ddccb73
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
17 changes: 16 additions & 1 deletion libs/utilities.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include "utilities.h"

int getStrLength(char* str) {
int length = 0;
Expand All @@ -9,4 +10,18 @@ int getStrLength(char* str) {
};

return length;
}
}

void printDashboard(TGame* pGame){

int i,j;

for(i=0;i<pGame->rows;i++){
for(j=0;j<pGame->cols; j++){
printf("%d ",pGame->dashboard[i][j]);
}
printf("\n");
}


}
21 changes: 21 additions & 0 deletions libs/utilities.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#ifndef UTILITIES_H_INCLUDED
#define UTILITIES_H_INCLUDED

#define ROWS 100
#define COLS 100

typedef struct{

int dashboard[ROWS][COLS];
int rows;
int cols;
int cellAlive;
int cellDead;

}TGame;







/**
* @brief Calculates the length of a string.
*
Expand All @@ -17,4 +36,6 @@
*/
int getStrLength(char* str);

void printDashboard(TGame* pGame);

#endif // UTILITIES_H_INCLUDED
17 changes: 14 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@
#include <stdlib.h>

int main() {
char str[] = "Hello World!";
int strLength = getStrLength(str);

printf("> The length of the string \"%s\" is %d.", str, strLength);
int dashboard[ROWS][COLS];
int rows=ROWS;
int cols=COLS;
int cellAlive;
int cellDead;

TGame game;

game.dashboard=dashboard;
game.rows=rows;
game.cols=cols;
game.cellAlive=cellAlive;
game.cellDead=cellDead;

printDashboard(&game);
return 0;
}

0 comments on commit ddccb73

Please sign in to comment.