First commit

This commit is contained in:
2023-03-28 08:08:11 -05:00
commit b048b09f64
5 changed files with 127 additions and 0 deletions

46
main.c Normal file
View File

@@ -0,0 +1,46 @@
#include "message.h"
#include "user.h"
#include <stdio.h>
int main() {
User[num_of_lines("user_file.txt")] users;
FILE* fp = fopen("user_file.txt", "w+");
Message message = new_message("Hello, this is a text message",user1,user2);
printf("Message was: %s\nSentfrom: %s\nSent to: %s\nSent at: %s\n",message.text,message.sender.username,message.recipient.username,asctime(&message.timeinfo));
}
/* Finds the number of lines in a file (Which MUST end in a new-line, if the last
line is to be counted) */
int num_of_lines(char* filename) {
int num_lines = 0;
FILE* fp = fopen(filename,"r");
if (fp == NULL) {
return -1;
}
for (int c = getc(fp); c != EOF; c = getc(fp)) {
if (c == '\n') {
num_lines++;
}
}
fclose(fp);
return num_lines;
}