KRUGSON
2 years ago
13 changed files with 67 additions and 71 deletions
-
3src/c/helper.h
-
2src/c/items.c
-
12src/c/main.c
-
2src/c/map.h
-
43src/c/nav_helper.c
-
13src/c/nav_helper.h
-
38src/c/utils.c
-
8src/c/utils.h
-
3test/c/test_commands.c
-
3test/c/test_items.c
-
3test/c/test_map.c
-
3test/c/test_player.c
-
5test/c/test_utils.c
@ -1,43 +0,0 @@ |
|||
//bibs |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <stdbool.h> |
|||
|
|||
//headers |
|||
#include "nav_helper.h" |
|||
|
|||
bool startsWith(const char *a, const char *b) |
|||
{ |
|||
if (strncmp(a, b, strlen(b)) == 0) |
|||
return 1; |
|||
return 0; |
|||
}; |
|||
|
|||
FILE *getStream(char *filePath) |
|||
{ |
|||
FILE *stream; |
|||
stream = fopen(filePath, "r"); |
|||
if (stream == NULL) |
|||
{ |
|||
printf("ERROR: couldn't open or find file: %s !\n", filePath); |
|||
exit(EXIT_FAILURE); // exit |
|||
} |
|||
|
|||
return stream; |
|||
} |
|||
|
|||
void printStreamLines(FILE *stream){ |
|||
|
|||
char *line = NULL; |
|||
size_t len = 0; |
|||
ssize_t read; |
|||
|
|||
/* print line by line from file */ |
|||
while ((read = getline(&line, &len, stream)) != -1) |
|||
{ |
|||
// printf("Retrieved line of length %u :\n", read); |
|||
printf("%s", line); |
|||
} |
|||
|
|||
free(line); /* Deallocate allocated memory */ |
|||
} |
@ -1,13 +0,0 @@ |
|||
#ifndef NAV_HELPER_H |
|||
#define NAV_HELPER_H |
|||
|
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <stdbool.h> |
|||
#include <string.h> |
|||
|
|||
bool startsWith(const char *a, const char *b); |
|||
FILE *getStream(char *filePath); |
|||
void printStreamLines(FILE *stream); |
|||
|
|||
#endif |
@ -1,7 +1,15 @@ |
|||
#ifndef UTILS_H |
|||
#define UTILS_H |
|||
|
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <stdbool.h> |
|||
#include <string.h> |
|||
|
|||
int randomIntRange(int min, int max); |
|||
int map(int x, int in_min, int in_max, int out_min, int out_max); |
|||
bool startsWith(const char *a, const char *b); |
|||
FILE *getStream(char *filePath); |
|||
void printStreamLines(FILE *stream); |
|||
|
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue