it kinda works...

This commit is contained in:
randomuser 2020-11-02 21:38:22 -06:00
parent b99ea96de3
commit 6ca1d7e4b0
1 changed files with 12 additions and 6 deletions

18
main.c
View File

@ -4,7 +4,7 @@
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#define DATFILE "/home/randomuser/datfile" #define DATFILE "/home/ryan/datfile"
time_t buf; time_t buf;
struct tm bt; struct tm bt;
@ -87,13 +87,19 @@ int timediff(struct tm f, struct tm l) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc != 2) { if (argc != 2) {
FILE *f = fopen(DATFILE, "a"); FILE *f = fopen(DATFILE, "r");
char *line; char line[2048];
struct session buffer; struct session session_array[20];
int counter = 0;
while(fgets(line, sizeof(line), f)) { while(fgets(line, sizeof(line), f)) {
buffer = line_to_session(&line); session_array[counter] = line_to_session(line);
write_session(f, buffer); counter++;
}
fclose(f);
FILE *fd = fopen(DATFILE, "a+");
for(int x = 0; x < counter; x++) {
write_session(fd, session_array[x]);
} }
return 1; return 1;
} }