Click here to Skip to main content
15,749,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
program is about implementation on circular queue:


main.c:58:34: error: expected ‘)’ before ‘cqueue’
         printf("%d was deleted\n"cqueue[front]);
                                  ^~~~~~
main.c:58:18: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
         printf("%d was deleted\n"cqueue[front]);
                  ^
main.c: In function ‘display’:
main.c:85:26: error: expected ‘)’ before ‘cqueue’
             printf("%d\n"cqueue[CAPACITY]);
                          ^~~~~~
main.c:85:22: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
             printf("%d\n"cqueue[CAPACITY]);
                      ^


What I have tried:

C++
#include<stdio.h>
#define CAPACITY 5
int cqueue[CAPACITY];
int front=-1,rear=-1;
void enQueue(int x);
void deQueue();
void display();
int main()
{
    enQueue(5);
    enQueue(4);
    enQueue(3);
    enQueue(2);
    enQueue(1);
    deQueue();
    deQueue();
    deQueue();
    enQueue(6);
    enQueue(7);
    enQueue(8);
    display();
    
}
void enQueue(int x)
{
    if(((rear==(CAPACITY-1))&&(front==0))||(front==(rear+1)))
    {
        printf("cqueue is full\n");
    }
    else
    if((front==-1)&&(rear==-1))
    {
        front,rear=0;
        cqueue[rear]=x;
    }
        else
        if(rear==(CAPACITY-1))
        {
            rear=0;
            cqueue[rear]=x;
        }
        else
        {
            rear++;
            cqueue[rear]=x;
            printf("%d element was inserted\n",cqueue[rear]);
        }
}
void deQueue()
{
    if(front==-1)
    {
        printf("cqueue is empty\n");
    }
    else
    if(front==(CAPACITY-1))
    {
        printf("%d was deleted\n"cqueue[front]);  // error here  
        front=0;
        
    }
    else
    if(front==rear)
    {
        front=-1;
        rear=-1;
    }
    else
    {
        printf("%d was deleted\n",cqueue[front++]);
    }
}

void display()
{
    int i,j;
    if(front<=rear)
        for(i=front;i<=rear;i++)
        {
            printf("%d\n",cqueue[i]);
        }
        else
        {for(i=front;i<=(CAPACITY-1);i++)
        {
            printf("%d\n"cqueue[CAPACITY]);   //error here
        }
        for(j=0;j<=rear;j++)
        {
            printf("%d\n",cqueue[CAPACITY]);
        }
    }
}
Posted
Updated 7-May-21 20:49pm

Look at the error message, and at the code it describes - you have a lot of information there:
main.c:58:34: error: expected ‘)’ before ‘cqueue’
         printf("%d was deleted\n"cqueue[front]);
                                  ^~~~~~
Let's break it down:
main.c:58:34: error: expected ‘)’ before ‘cqueue’
^       ^  ^         ^
|       |  |         Error message
|       |  --------- Column number
|       ------------ Line number
---------------------File name

So, the error is in "main.c", on line 58, column 34, and it's complaining that it "expected ‘)’ before ‘cqueue’"
It then shows you line 58 and points at where it found the problem, just to be helpful:
C
printf("%d was deleted\n"cqueue[front]);
                         ^~~~~~

So look at the code: it's saying it expected the printf function call to end after the format string, but it found something it didn't understand.
Hmmm ... shouldn't there be a comma between the format string and the parameters?
C
printf("%d was deleted\n", cqueue[front]);
Try that, and some of your other errors will go away at the same time!
 
Share this answer
 
Comments
_-_-_-me 8-May-21 2:47am    
Okay, many thanks!
OriginalGriff 8-May-21 3:15am    
You're welcome!

Remember, you are going to be getting lots of syntax errors in the future - we all do - so it's worth trying to get used to "how the compiler thinks" so you can fix then on your own. It's a lot, lot faster in the long run than asking others about every single syntax problem! :laugh:
_-_-_-me 9-May-21 4:21am    
Okay , I will try to fix the syntax errors on my own. Thank you for offering your valuable advice.
OriginalGriff 9-May-21 4:42am    
It really isn't that complicated, and it's something we all do many times a day - so it really does save you a huge amount of time being able to work them out for yourself!

The problem comes when you read what you meant to write instead of what you did ... and I do that all the damn time :laugh:
Programme :




C++
#include<stdio.h>
#define CAPACITY 5
int cqueue[CAPACITY];
int front=-1,rear=-1;
void enQueue(int x);
void deQueue();
void display();
int main()
{
    enQueue(5);
    enQueue(4);
    enQueue(3);
    enQueue(2);
    enQueue(1);
    enQueue(0);
    deQueue();
    deQueue();
    deQueue();
    enQueue(6);
    enQueue(7);
    enQueue(8);
    printf("%d    %d\n",front,rear);
    display();
    
}
void enQueue(int x)
{
    if(((rear==(CAPACITY-1))&&(front==0))||(front==(rear+1)))
    {
        printf("cqueue is full\n");
    }
    else
  {  if((front==-1)&&(rear==-1))
    {
        front=0;
        rear=0;          
        cqueue[rear]=x;
        printf("%d element was added\n",cqueue[rear]);
    }
        else
       { if(rear==(CAPACITY-1))
        {
            rear=0;
            cqueue[rear]=x;
            printf("%d was added\n",cqueue[rear]);
        }
        else
        {
            rear++;
            cqueue[rear]=x;
            printf("%d element was inserted\n",cqueue[rear]);
        }}}
}
void deQueue()
{
    if(front==-1)
    {
        printf("cqueue is empty\n");
    }
    else
    if(front==(CAPACITY-1))
    {
        printf("%d was deleted\n",cqueue[front]);  
        front=0;
        
    }
    else
    if(front==rear)
    {
        front=-1;
        rear=-1;
    }
    else
    {
        printf("%d was deleted\n",cqueue[front++]);
    }
}

void display()
{
    int i,j;
    if(front<=rear)
        for(i=front;i<=rear;i++)
            printf("%d\n",cqueue[i]);
        else
        {
            for(i=front;i<=(CAPACITY-1);i++)
            printf("%d\n",cqueue[i]);   
            for(j=0;j<=rear;j++)
            printf("%d\n",cqueue[j]);
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900