Took 'user*' as a parameter instead of 'user', returned 'Message*' instead of 'Message'

master
Aadhavan Srinivasan 2 years ago
parent ad70f43da9
commit 2c46754cb4

@ -4,14 +4,22 @@
#include <time.h> #include <time.h>
#include "message.h" #include "message.h"
Message new_message(char* string, User from, User to) { Message* new_message(char* string, User* from, User* to) {
Message new_message; Message* new_message;
new_message.text = malloc((strlen(string)+1)*sizeof(char)); new_message = malloc(sizeof(Message));
strcpy(new_message.text,string); new_message->text = malloc((strlen(string)+1)*sizeof(char));
strcpy(new_message->text,string);
new_message.sender = from; new_message->sender = malloc(sizeof(User));
new_message.recipient = to; new_message->recipient = malloc(sizeof(User));
memcpy(new_message->sender, from, sizeof(User));
memcpy(new_message->recipient, to, sizeof(User));
// *(new_message->sender) = *from;
// *(new_message->recipient) = *to;
time_t rawtime; time_t rawtime;
struct tm timeinfo; struct tm timeinfo;
@ -19,7 +27,7 @@ Message new_message(char* string, User from, User to) {
time(&rawtime); time(&rawtime);
timeinfo = *localtime(&rawtime); timeinfo = *localtime(&rawtime);
new_message.timeinfo = timeinfo; new_message->timeinfo = timeinfo;
return new_message; return new_message;

@ -11,10 +11,10 @@ typedef struct Message_s Message;
struct Message_s { struct Message_s {
char* text; char* text;
struct tm timeinfo; struct tm timeinfo;
User sender; User* sender;
User recipient; User* recipient;
}; };
Message new_message(char* text,User from,User to); Message* new_message(char* text,User* from,User* to);
#endif #endif

Loading…
Cancel
Save