Hi any expert know what wrong's with this? I have 102 syntax error. I am suspecting did i miss out identify #include something like #include stdio.lib or? Please help me! thanks! I have been posting entries but none of the expert solved this. So hope you do, thanks! By the way I am using Microsoft Visual C++ 2010 Express, win console application.
#include<stdio.h>
#include<iostream>
#define MAX 30
using namespace std;
typedef struct pqueue
{
char str[MAX];
int priority;
pqueue* next;
}pqueue;
int enqueuepriority(pqueue *&pq, char str[MAX], int priority)
{
if(priority>0)
{
pqueue *p=(pqueue*)malloc(sizeof(pqueue));
for(int i=0;i<MAX;i++)
p->str[i]=str[i];
p->priority=priority;
p->next=pq->next;
pq->next=p;
return 1;
}
else return 0;
}
char* dequeue(pqueue *&pq)
{
pqueue *p;
if(pq->next!=NULL)
{
p=pq->next;
pq->next=pq->next->next;
return p->str;
}
else return "";
}
int main()
{
cout<<"(1) Enqueue (single)"<<endl;
cout<<"(2) Enqueue (multiple)"<<endl;
cout<<"(3) Dequeue (single)"<<endl;
cout<<"(4) Dequeue (all)"<<endl;
cout<<"(5) Quit"<<endl;
int re=0,t=1;
static char* str=new char[MAX];
int priority=0;
pqueue *pq=(pqueue*)malloc(sizeof(pqueue));
pq->next=NULL;
while(re!=5)
{
cout<<"Choose an action:";
cin>>re;
switch(re)
{
case 1:
cout<<"Enter a name to save and its priority"<<endl;
scanf("%s%d",str,&priority);
if(enqueuepriority(pq,str,priority))
break;
else
{
cout<<"INPUT ERROR!!"<<endl;
break;
}
case 2:
cout<<"Enter names to save and their priority. Enter “done” to quit"<<endl;
do
{
scanf("%s",str);
if(strcmp(str,"done")!=0)
{
scanf("%d",&priority);
enqueuepriority(pq,str,priority);
}
else t=0;
}while(t==1);
break;
case 3:
str=dequeue(pq);
if(str=="")
cout<<"NULL"<<endl;
else
printf("%s\n",str);
break;
case 4:
while(pq->next!=NULL)
{
printf("%s\n",dequeue(pq));
}
break;
case 5: break;
default:
cout<<"INPUT ERROR!!"<<endl;
break;
}
}
delete [] str;
return 0;
}