Added day predictor
This commit is contained in:
parent
2f7a9209d8
commit
ced29a1974
34
haiku.c
34
haiku.c
@ -2,6 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/random.h>
|
||||
#include <errno.h>
|
||||
|
||||
// Function to pick a random word/phrase from an array
|
||||
const char *randomWord(const char *words[], int size)
|
||||
@ -204,12 +205,35 @@ const char *randomLocation()
|
||||
return randomWord(locations, sizeof(locations) / sizeof(locations[0]));
|
||||
}
|
||||
|
||||
int main()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int days = 1;
|
||||
|
||||
srand(time(NULL) / 86400); // today's haiku
|
||||
// Construct a poem with 6 lines
|
||||
// printf("An Hermetic Poem:\n\n");
|
||||
if (argc > 1)
|
||||
{
|
||||
// error check strtol
|
||||
char *endptr;
|
||||
errno = 0;
|
||||
days = strtol(argv[1], &endptr, 10);
|
||||
if (errno != 0 || endptr == argv[1] || *endptr != '\0' || days <= 0)
|
||||
{
|
||||
fprintf(stderr, "Could not convert argument to integer\n");
|
||||
printf("Usage: %s [days]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int day = 0; day < days; day++)
|
||||
{
|
||||
|
||||
if (days != 1)
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
t += day * 86400;
|
||||
struct tm tm = *localtime(&t);
|
||||
printf("%d-%02d-%02d ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
}
|
||||
srand(time(NULL) / 86400 + day);
|
||||
|
||||
int verseCount = 1; // haiku
|
||||
for (int i = 0; i < verseCount; i++)
|
||||
@ -519,6 +543,6 @@ int main()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user