From 296059e911834be66e30cafcb2358ad620a5743f Mon Sep 17 00:00:00 2001 From: Arthur-Coppey Date: Sun, 18 Apr 2021 03:13:53 +0200 Subject: [PATCH] start quote selection implementation --- CMakeLists.txt | 2 +- quote.c | 24 ++++++++++++++++++++++++ quote.h | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 quote.c create mode 100644 quote.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 15e4c45..32c9999 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,4 +3,4 @@ project(qotd C) set(CMAKE_C_STANDARD 99) -add_executable(qotd main.c) \ No newline at end of file +add_executable(qotd main.c quote.c quote.h server.c server.h) \ No newline at end of file diff --git a/quote.c b/quote.c new file mode 100644 index 0000000..5151676 --- /dev/null +++ b/quote.c @@ -0,0 +1,24 @@ +// +// Created by k0rb4k on 30/03/2021. +// + +#include "quote.h" + +void getRandomQuote(char quote[1024]) { + // TODO: true random between 0 and number of lines in file + int rand = 0; + getQuote(rand, quote); +} + +void getQuote(int line, char quote[1024]) { + FILE* list; +// char quote[1024]; + + // TODO: get specified x line + + list = fopen("quotes.txt", "r"); + + fgets(quote, 1024, list); + + fclose(list); +} diff --git a/quote.h b/quote.h new file mode 100644 index 0000000..a18b61e --- /dev/null +++ b/quote.h @@ -0,0 +1,16 @@ +// +// Created by k0rb4k on 30/03/2021. +// + +#ifndef QOTD_QUOTE_H +#define QOTD_QUOTE_H + +#include +#include +#include + +void getRandomQuote(char quote[1024]); + +void getQuote(int line, char quote[1024]); + +#endif //QOTD_QUOTE_H