diff --git a/data/test.txt b/data/test.txt new file mode 100644 index 0000000..7ee7d40 --- /dev/null +++ b/data/test.txt @@ -0,0 +1,4 @@ +hey, how are you? +i'm fine. thank you! +then what you think? +nothing! \ No newline at end of file diff --git a/test b/test new file mode 100755 index 0000000..b10cf93 Binary files /dev/null and b/test differ diff --git a/tests/readFileFromText.c b/tests/readFileFromText.c new file mode 100644 index 0000000..b8d07e7 --- /dev/null +++ b/tests/readFileFromText.c @@ -0,0 +1,47 @@ +#include +#include +#include + +struct list +{ + char *text; + struct list *next; +}; + +typedef struct list LIST; + +int main(void) +{ + FILE *file; + char line[128]; + LIST *current, *head; + + head = current = NULL; + file = fopen("./data/test.txt", "r"); + + while (fgets(line, sizeof(line), file)) + { + LIST *node = malloc(sizeof(LIST)); + node->text = strdup(line); + node->next = NULL; + + if (head == NULL) + { + current = head = node; + } + else + { + current = current->next = node; + } + } + + // close the file + fclose(file); + + for (current = head; current; current = current->next) + { + printf("%s", current->text); + } + + return 0; +} \ No newline at end of file