Move into directory
CMake / build (push) Failing after 4s

This commit is contained in:
2025-02-28 11:40:57 +01:00
parent 294389980b
commit e078a1023a
8 changed files with 23 additions and 15 deletions
+67
View File
@@ -0,0 +1,67 @@
//
// Created by k0rb4k on 30/03/2021.
//
#include "quote.h"
#include "config.h"
void getRandomQuote(char quote[2048])
{
int lineCount;
long line;
if ((lineCount = getFileLineCount(QUOTES_FILE)) == -1)
{
puts("file does not exist");
exit(-1);
}
line = rand() % lineCount;
getQuote(line, quote);
}
void getQuote(long line, char quote[2048])
{
FILE *list;
list = fopen(QUOTES_FILE, "r");
/*skip lines*/
while (line > 0)
{
if (fgetc(list) == '\n')
{
line--;
}
}
fgets(quote, 2048, list);
quote[strlen(quote) - 1] = '\0';
fclose(list);
}
int getFileLineCount(char *filename)
{
char c;
int lineCount = 0;
FILE *quotesFile = fopen(filename, "r");
if (quotesFile == NULL)
{
printf("no quote file found at \"%s\"\n", filename);
return -1;
}
while ((c = (char)fgetc(quotesFile)) != EOF)
{
if (c == '\n')
{
lineCount++;
}
}
fclose(quotesFile);
return lineCount;
}