Browse Source

refactoring: added func to print lines of stream

remotes/origin/fdai7372-main-patch-93194
KRUGSON 2 years ago
parent
commit
22c41a6cd0
  1. 14
      src/c/main.c
  2. 16
      src/c/nav_helper.c
  3. 1
      src/c/nav_helper.h

14
src/c/main.c

@ -69,20 +69,8 @@ int main()
void printInit()
{
FILE *stream;
char *line = NULL;
size_t len = 0;
ssize_t read;
stream = getStream(gameInstructionsFile);
/* 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 */
printStreamLines(stream);
fclose(stream); /* closing file */
acceptInstructions();

16
src/c/nav_helper.c

@ -25,3 +25,19 @@ FILE *getStream(char *filePath)
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
src/c/nav_helper.h

@ -8,5 +8,6 @@
bool startsWith(const char *a, const char *b);
FILE *getStream(char *filePath);
void printStreamLines(FILE *stream);
#endif
Loading…
Cancel
Save