I can't understand what's wrong with this code. I get a couple of
C2227: left of '->status' must point to class/struct/union/generic type
C2065: 'head' : undeclared identifier
and
C3861: 'main': identifier not found
I want to access the status of the item located in queue's head and change its value between the 3 status given in define.But I am doing something wrong while trying to access it that I have no idea about. Here's the code :
#define TOTALPACKETS 100
#define WINDOW 5
#define ACK 2
#define PENDING 1
#define NEW 0
typedef int Item ;
typedef struct node *link;
struct node{
Item data;
Item status;
link next;
};
int QUEUEempty(link head){
return head==NULL;
}
void QUEUEput(link *head, link *tail, Item data, Item status){
if (*head==NULL){
(*tail)=(link)malloc(sizeof(node));
(*tail)->data=data;
(*tail)->next=NULL;
(*tail)->status=NEW;
*head=*tail;
return;}
(*tail)->next=(link)malloc(sizeof(node));
*tail=(*tail)->next;
(*tail)->data=data;
(*tail)->next=NULL;
(*tail)->status=NEW;
return;
}
Item QUEUEget(link *head){
Item data=(*head)->data;
link t=*head;
*head=(*head)->next;
free(t);
return data;
}
void send(int sPacket){
(*head)->status=PENDING;//c2227,c2065
printf("Packet No. %d: %d",sPacket,*head->status);//c2227,c2065
}
void receive(){
if ((*head)->status==PENDING || (*head)->status=NEW) {//c2227,c2065
(*head)->status=ACK; //c2227,c2065
}
}
int main() {
int i,j,k,packets=0;
link head=NULL,tail=NULL;
for(i=0;i<TOTALPACKETS;i++){
QUEUEput(&head,&tail,i,NEW);
packets++;
}
while(!QUEUEempty(head)){
for (j=0;j<WINDOW;j++){
k=TOTALPACKETS-packets;
send(k);
receive();
if ((*head).status==ACK){
printf("Packet No. %d: %d",k,*head->status);
QUEUEget(&head);
}
}
}
return 0;
}