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;
}

When I look up 102 syntax error it relates to improper syntax after last legal syntax in command line arguments. If you are using the command line to open the program instead of the IDE then post the exact syntax you use on the command line.

Please post the exact error message and the line it refers to.

It is generally advised that you don't mix C and C++ intake/output methods in the same program unless you have to or unless you know exactly what you are doing.

In C++ the keyword typedef is not necessary when declaring user defined types.

malloc() goes with free(C style memory management)and new goes with delete (C++ memmory management). Don't try to release memory that you allocate with mall0c() using delete.

You don't use dynamic memory to declare memory for str so don't suse delete to release memory being used by str.

p does use dynamic memory so you should take responsibiltiy to release it.

There may be other concerns, but addressing these will probably make a big difference.

This article has been dead for over six months. Start a new discussion instead.