I have 102 Errors, may i know why it is this case?

won212's Avatar, Join Date: Mar 2012
Go4Expert Member
I have 102 Errors, may i know why it is this case? :O
Any solution to this?

Code:
 
#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;
}
peermhd's Avatar, Join Date: Apr 2012
Newbie Member
Code:
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#define MAX 30
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;
}

Last edited by shabbir; 5Apr2012 at 17:24.. Reason: Code blocks
won212's Avatar, Join Date: Mar 2012
Go4Expert Member
Hi expert, thanks for the amendment!
Would like to ask i got the error is it because i did not specify #include<string.h>?
However when i tried to preview your code, I got error like "Error 1 error C1083: Cannot open include file: 'iostream.h': No such file or directory"? & " 2 IntelliSense: cannot open source file "iostream.h"?

Quote:
Originally Posted by peermhd View Post
Code:
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#define MAX 30
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;
}
won212's Avatar, Join Date: Mar 2012
Go4Expert Member
Quote:
Originally Posted by won212 View Post
Hi expert, thanks for the amendment!
Would like to ask i got the error is it because i did not specify #include<string.h>?
However when i tried to preview your code, I got error like "Error 1 error C1083: Cannot open include file: 'iostream.h': No such file or directory"? & " 2 IntelliSense: cannot open source file "iostream.h"?
Hi, thanks for the posting however, I got error like "Error1:error C1083: Cannot open include file: 'iostream.h':"