Please help debug
I just included the relavent portions of the program. My errors seem to be in my enqueue function.
The errors are syntactical. I need a second set of eyes to determine where the errors are.
Two parse errors and two data misrepresentations...
Thank you!
typedef struct Data /*struct*/
{
unsigned char byte;
struct Data *next;
}data;
.
.
.
int enqueue(data **head, data **tail, unsigned char data)
{ /*This adds the data byte to the que.*/
data *hold,*new; /*Placeholders*/
if(*head==NULL) /*If que is empty.*/
{
new=(data *) malloc(sizeof(data));
if(new==NULL) /*if no memory allocated.*/
{
printf("No Memory Allocated, enqueue.nn");
return(1);
}
new->byte=data;
new->next=NULL; //copies over and sets up.
*head=new;
*tail=new;
return(0);
}
if(*head!=NULL) //otherwise que is full.
{
new=(data *) malloc(sizeof(data));
hold=*head;
new->byte=data; //Add data byte to que.
new->next=hold;
*head=new;
}
}/*end enqueue*/
int dequeue(data **head, data **tail)
{ /*Deletes the que.*/
data *temp,*hold;
if(*tail==NULL) /*que already empty.*/
{
return(-1);
}
if(*head == *tail) /*if que only has one left.*/
{
free(head);
*head=NULL;
*tail=NULL;
return(-1);
}
else /*goes through que to get to the tail.*/
{
temp=*head;
while(temp->next != *tail)
{
temp=temp->next;
}
temp->next=NULL;
free(tail); /*cuts off the last variable. */
*tail=temp;
return(1);
}
}/*end dequeue*/
prompt@psi >cat new.cpicogcc -o new
new.c: In function `enqueue':
new.c:309: `hold' undeclared (first use in this function)
new.c:309: (Each undeclared identifier is reported only once
new.c:309: for each function it appears in.)
new.c:309: `new' undeclared (first use in this function)
new.c:313: parse error before `)'
new.c:329: parse error before `)'
prompt@psi >exit
By OTA: Amrit Lal Ahuja, PhD (IP)
OTA Rating: 4.9/5
Your Price: $2.19 (original value ~$15.96)
What's included:
Page generated in 0.011 seconds