Hello,
I am trying to implement a message storage (string type) and retrieval functionality, where I have 3 c files:
main.c
sender.c --> this will have send function
receiver.c --> this will have receive function
main.c needs to call the sender.c send to store the message and
main.c needs to call the receiver.c receive to get the message in FIFO.
So far to do this, I have created a new msgs.h file, sender.c and receiver.c
But with this, I am getting compilation errors as my micro controller don't have malloc library. Is there any alternative and workable solution to do this?
Code:
//msgs.h
#define MAXMESSGS 10
struct node
{
char* data[10]; //--> I guess this is also not correct
struct node *link;
}*front, *rear;
Code:
//sender.c
#include <msgs.h>
send() {
// SOME OTHER STUFF
struct node *temp;
temp = (struct node*)malloc(sizeof(struct node));
temp->data = msg;
temp->link = NULL;
if (rear == NULL)
{
front = rear = temp;
}
else
{
rear->link = temp;
rear = temp;
}
}
Code:
//receiver.c
#include <msgs.h>
receive ()
{
// SOME OTHER STUFF
struct node *temp;
temp = front;
if (front == NULL)
{
printf("queue is empty \n");
front = rear = NULL;
}
else
{
msg=front->data;
front = front->link;
free(temp);
}
return msg;
}
Errors:
Code:
sender.c: undefined reference to malloc
receiver.c: undefined reference to free