I have 102 Errors for this priority queue

I have 102 Errors, may i know why it is this case? :O
Any solution to this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#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;
}
There're often follow up errors. Solve the first error and a lot of other go away as well. So post at least the first error if you want help with that.

Forgetting a brace is a candidate where you get loads of errors.

Lines 60 to 64 are certainly misplaced there.
I think i may have forgot to state this.

#include<stdlib.h>
#include<string.h>

but now, i got errors like "Error 1 error C1083: Cannot open include file: 'iostream.h': No such file or directory"? & " 2 IntelliSense: cannot open source file "iostream.h"?
IT is just
#include <iostream>, not #include <iostream.h>


Also, I tried compiling on my machine (VS2010) and this works for me. I added some indenting here while I was looking for potential problems. If you don't properly format, it's nearly impossible to read effectively and most people won't bother reading your code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#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;
}


Just a modification in the code ...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#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  &&  pq != NULL)
		{
					pqueue *p=(pqueue*)malloc(sizeof(pqueue));		
					strcpy( p->str, str );
					p->priority=priority;
					p->next=pq->next;
					pq->next=p;		
					return 1;
		}
		else
	{
					pqueue *p=(pqueue*)malloc(sizeof(pqueue));		
					strcpy( p->str, str );
					p->priority=priority;
					pq = p ; 
					return 1;
	}
	return 0; 
}
char* dequeue(pqueue *&pq)
{
			pqueue *p;
			char str[MAX]; 
			memset( str , 0 , sizeof ( str) / sizeof (char) );
			cout<<"\n Enter the name ";
			cin>>str; 
		if(pq !=NULL)
		{

				pqueue *p=(pqueue*)malloc(sizeof(pqueue));		
				strcpy( p->str, str );
				p->priority=priority;
				p->next=pq->next;
				pq->next=pq->next->next;
				
			}
			
			return (char*)&str ;
}

int main()
{
		int re=0,t=1;
		static char* str=new char[MAX];
		int priority=0;
		cout<<"(1) Enqueue (single)"<<endl;
		cout<<"(2) Enqueue (multiple)"<<endl;
		cout<<"(3) Dequeue (single)"<<endl;
		cout<<"(4) Dequeue (all)"<<endl;
		cout<<"(5) Quit"<<endl;

		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)) 
													else
														cout<<"Input Error";
							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;
while( pq!= NULL ) 
 {  
        pqueue * temp = pq;
        pq = pq->next;   
        delete temp;        

 }
return 0;
}
Last edited on
Stewbond, I tried your code in my VS C++ 2010 express, it couldn't works. I just changed cout, sin to printf and scanf. Is this way it wont works for me but work for u?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#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()
{
	printf("(1) Enqueue (single)");
	printf("(2) Enqueue (multiple)");
	printf("(3) Dequeue (single)");
	printf("(4) Dequeue (all)");
	printf("(5) Quit");

	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)
	{
		printf("Choose an action:");
		scanf("%i",re);
		switch(re)
		{
		case 1:
			printf("Enter a name to save and its priority");
			scanf("%s%d",str,&priority);
			if(enqueuepriority(pq,str,priority)) 
				break;
			else
			{
				printf("INPUT ERROR!!");
				break;
			}
		case 2:
			printf("Enter names to save and their priority. Enter “done” to quit");
			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=="")
				printf("NULL");
			else
				printf("%s\n",str);
			break;
		case 4:
			while(pq->next!=NULL)
			{
				printf("%s\n",dequeue(pq));
			}   
			break;
		case 5: 
			break;
		default:
			printf("INPUT ERROR!!");
			break;
		}
         
	}
	delete  [] str;
	return 0;
}
bluecoder, I tried debug your code, it looks fine, but when i tried to enter the details inside, typing "4" on the cmd should give me all the words to be dequeue and not enter a name?
as per code the case 4 : does not enter the name , it only display the name in the vector
hi bluecoder, and now, i debug your code, I get the same 100++ syntax error, suspecting did i miss out specifying #.. on top or?
Topic archived. No new replies allowed.