0
votes

when compiled i receive these messages

[error] variable or field 'Enqueue' declared void 49 14 C:\weblinky1.cpp [Error] variable or field 'enqueue' declared void

49 20 C:\weblinky1.cpp [Error] no match for 'operator*' (operand types are 'documents' and 'node')

49 35 C:\weblinky1.cpp [Error] no match for 'operator*' (operand types are 'documents' and 'node')

49 45 C:\weblinky1.cpp [Error] expected primary-expression before 'struct'

50 14 C:\weblinky1.cpp [Error] variable or field 'dequeue' declared void

50 20 C:\weblinky1.cpp [Error] no match for 'operator*' (operand types are 'documents' and 'node')

51 14 C:\weblinky1.cpp [Error] variable or field 'getRear' declared void

51 20 C:\weblinky1.cpp [Error] no match for 'operator*' (operand types are 'documents' and 'node*')

52 15 C:/weblinky1.cpp [Error] variable or field 'getFront' declared void

52 21 C:\weblinky1.cpp [Error] no match for 'operator*' (operand types are 'documents' and 'node*')

C:\Users\marshalee\Desktop\DSLabTest1_1300054246\weblinky1.cpp In function 'int main()':

60 11 C:\weblinky1.cpp [Error] no match for 'operator*' (operand types are 'documents' and 'node*')

114 49 C:\weblinky1.cpp [Error] 'enqueue' was not declared in this scope

122 39 C:\weblinky1.cpp [Error] 'dequeue' was not declared in this scope

126 27 C:\weblinky1.cpp [Error] no match for 'operator==' (operand types are 'documents' and 'long long int')

138 42 C:\weblinky1.cpp [Error] 'deletedocsize' was not declared in this scope

147 48 C:\weblinky1.cpp [Error] 'searchfoldername' was not declared in this scope

157 32 C:\weblinky1.cpp [Error] 'searchID' was not declared in this scope

165 33 C:\weblinky1.cpp [Error] 'averagedocsize' was not declared in this scope

173 29 C:\weblinky1.cpp [Error] could not convert 'isEmpty()' from 'void' to 'bool'

182 36 C:\weblinky1.cpp [Error] 'getRear' was not declared in this scope

193 45 C:\weblinky1.cpp [Error] 'getFront' was not declared in this scope

C:\weblinky1.cpp At global scope:

221 19 C:\weblinky1.cpp [Error] variable or field 'enqueue' declared void

bellow is my complete code

    enter code here/**
 * Queue implementation using linked list in C.
 */

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

#define CAPACITY 100    // Queue max capacity


/* Queue structure definition */
   struct documents 
{
     int id;
    char docname[50];
    char foldername[50];
    float docsize;
    struct document * next;
    struct document * previous;

};    



//Delacre document variable
struct documents Queue;

//Create node for linked list
struct node
{
    struct documents Queue;
    struct node* previous;
    struct node* next;
};

// Creating an empty linked list
struct node * rear = NULL;
struct node * front = NULL;


/* Queue size */
unsigned int size = 0;


void enqueue(Queue ** rear, Queue ** front, struct documents Queue);
void dequeue(Queue ** front);
void getRear(Queue * rear);
void getFront(Queue * front);
void isEmpty();
void isFull();


int main()
{
    int ch, data;
    Queue *rear, *front;
     struct documents Queue;
    int id;
    float docsize;
    char* docname;
    char* foldername;

    rear  = NULL;
    front = NULL;

    /* Run indefinitely until user manually terminates */
    while (1)
    {
        /* Queue menu */
        printf("--------------------------------------------\n");
        printf("  QUEUE LINKED LIST IMPLEMENTATION PROGRAM  \n");
        printf("--------------------------------------------\n");
        printf("1. Enqueue\n");
        printf("2. Dequeue\n");
        printf("3. Delete by Size of Document\n");
        printf("4. Display Documents based on Folder Name\n");
        printf("5. Enter ID to Display Index where Documents was 
          found\n");
        printf("6. Display Document Size Average\n");
        printf("7. Size of the Queue\n");
        printf("8. Get Rear\n");
        printf("9. Get Front\n");
        printf("0. Exit\n");
        printf("--------------------------------------------\n");
        printf("Select an option: ");

        scanf("%d", &ch);


        /* Menu control switch */
        switch (ch)
        {
            case 1:

                 printf("\nEnter Document ID#: ");
                   scanf("%d", &Queue.id);
                    Queue.id = id;
                    printf("Enter Document size#: ");
                    scanf("%f", &Queue.docsize);
                     Queue.docsize = docsize;
                     printf("Enter Document name: ");
                      scanf("%s", &Queue.docname);
                       strcpy(Queue.docname, docname);
                       printf("Enter folder name: ");
                        scanf("%s", foldername);
                         strcpy(Queue.foldername, foldername);


                // Enqueue function returns 1 on success
                // otherwise 0
                if (enqueue(&rear, &front, Queue))
                    printf("Document added to queue.");
                else
                    printf("Queue is full.");

                break;

            case 2:
                Queue = dequeue(&front);

                // on success dequeue returns element removed

                if (Queue == NULL)
                    printf("Queue is empty.");
                else
                    printf("Queue => %d", Queue.front);

                break;

           //Delete by Size of Document
           case 3:

                 printf("Enter Document size: ");
                    scanf("%f", &docsize);
                    deletedocsize(docsize);

                break;

        //Display Documents based on Folder Name
        case 4:

                 printf("Enter Document Folder Name: ");
                     scanf("%s", foldername);
                    searchfoldername(foldername); 

                break;


        //Enter ID to Display Index where Documents was found
        case 5:

                 printf("Enter Document ID#: ");
                     scanf("%f", &id);
                    searchID(id); 

                break;


        //Display Document Size Average
        case 6:

                 averagedocsize(); 

                break;

            case 7: 

                // isEmpty() function returns 1 if queue is emtpy 
                // otherwise returns 0
                if (isEmpty())
                    printf("Queue is empty.");
                else 
                    printf("Queue size => %d", size);

                break;

            //get rear of document queue
            case 8: 
                data = getRear(rear);

                if (Queue == Queue.rear)
                    printf("Queue is empty.");
                else 
                    printf("Rear => %d", Queue.rear);

                break;

            case 9: 

                Queue = getFront(front);

                if (Queue == NULL)
                    printf("Queue is empty.");
                else 
                    printf("Front => %d", Queue.front);

                break;

            case 0:
                printf("Exiting from application.\n");
                exit(0);

            default:
                printf("Invalid choice, please input number between (0- 
       5).");
                break;
        }

        printf("\n\n");
    }
}



/**
 * Enqueues/Insert an element at the rear of a queue.
 * Function returns 1 on success otherwise returns 0.
 */
void enqueue(Queue *q)
{
     Queue * temp= NULL;

    // Check queue out of capacity error
    if (isFull())
    {
        return 0;
    }

    // Create a new node of queue type
    temp = (Queue *) malloc (sizeof(Queue));

    // Assign data to new node
    temp->docs= en;

    // Initially new node does not point anything
    temp->next = NULL;
    temp->previous = NULL;

    // Link new node with existing last node 
    if ( (*rear) )
    {
        (*rear)->next = temp;
    }


    // Make sure newly created node is at rear
    *rear = temp;

    // Link first node to front if its NULL
    if ( !( *front) )
    {
        *front = *rear;
    }

    // Increment quque size
    size++;

    return 1;
}


/**
 * Gets, element at rear of the queue. It returns the element
 * at rear of the queue on success otherwise return as 
 * error code.
 */
int getRear(Queue * rear)
{
    //  if queue is empty otherwise rear.
    return (isEmpty())
            ? NULL
            : rear->Queue.rear;
}


/**
 * Gets, element at front of the queue. It returns the element
 * at front of the queue on success otherwise return  as 
 * error code.
 */
int getFront(Queue * front)
{
    // if queue is empty otherwise front.
    return (isEmpty())
            ? NULL
            : front->Queue.front;
}


/**
 * Checks, if queue is empty or not.
 */
int isEmpty()
{
    return (size <= 0);
}


/**
 * Checks, if queue is within the maximum queue capacity.
 */
int isFull()
{
    return (size > CAPACITY);
}

// deleting any node based on position
void Delete(int n)
{
    struct documents temp1 =front;

      if(n == 1){
        front= temp1->next;
        free(temp1);
        return;
      }
      int i for(i =0; i<n-2; i++)
        temp1 = temp1->next;
      struct node* temp2 = temp1->next;
        temp1->next = temp2 -> next;
        free(temp2);
}

 //or using this method
void Dequeue(int n)
{
    struct documents temp1;

    if(Front == NULL)
    {
        printf("Queue is empty.\n");
    }
    else
    {
       int currentIndex = 0;
       struct documents *temp1 = (struct documents*)malloc(sizeof(struct 
        documents));
        bool traversing = true;


        tem1 = Front;
        temp1 = temp1->Queue;


        while(temp1 !=NULL) {
            if(temp1.id == n)
                {
                    temp1->previous->next=temp1->next;
                    free(temp1);
                printf("Item Deleted", currentIndex);
                return;
            }

            currentIndex++;

            temp1 = temp1->next;
            if (temp1 == NULL) {
                temp1 = temp1->previous;
            }
            temp1 = temp1->Queue;
        }
    }
}

//search by foldername
void searchfoldername(char foldername[])
{
    struct documents Queue;

    if(Front == NULL)
    {
        printf("Queue is empty.\n");
    }
    else
    {
    struct documents *tempp = (struct documents*)malloc(sizeof(struct 
     documents));
        bool traversing = true;
        int currIndex = 0;

        tempp = Front;
        tempy = tempp->Queue;
        Front = Front->next;

        while(traversing) {
            if(strcmp(tempy->foldername, foldername) == 0))
            {
                printf(" ID: %d\n", tempy->id);
                printf("Document Name: %s\n", tempy->docname);
                printf("Folder Name: %s\n", tempy->foldername);
                printf("Document Size: %d\n", tempy->docsize);
                printf("Document positioned at index: %d", currIndex);
                return tempy.foldername;
            }

            currIndex++;

            tempp = tempp->next;
            if (tempp == NULL) {
                tempp = tempp->previous;
            }
            tempy = tempp->Queue;
        }
    }
}

//delete document size
Void deletedocsize(int docsize)
{
    struct documents Queue;

    if(Front == NULL)
    {
        printf("Queue is empty.\n");
    }
    else
    {
        struct documents *tempp = (struct documents*)malloc(sizeof(struct 
          documents));
     bool traversE = true;
        int currIndex = 0;

        tempp = Front;
        tempy = tempp->Queue;
        front = front->next;
            while(traversE) {
            if(strcmp(tempy->docsize, docsize) <= Queue.docsize))

            {
                free(tempp);
                    return;
            }

            currIndex++;
              tempp = tempp->next;
            if (tempp == NULL) {
                tempp = tempp->previous;
            }
            tempy = tempp->Queue;
        }
    }
}
};

//Enter ID to Display Index where Documents was found
void searchID(int id)
{
    struct documents Queue;

    if(Front == NULL)
    {
        printf("Queue is empty.\n");
    }
    else
    {
        struct documents *tempp = (struct documents*)malloc(sizeof(struct 
         documents));
        bool traversing = true;
        int currIndex = 0;

        tempp = Front;
        tempy = tempp->Queue;
        Front = Front->next;

        while(traversing) {
            if(strcmp(tempy->id, id) == Queue.id))
            {
                printf("Document positioned at index: %d", currIndex);
                return tempy.id;
            }

            currIndex++;

            tempp = tempp->next;
            if (tempp == NULL) {
                tempp = tempp->previous;
            }
            tempy = tempp->Queue;
        }
    }
}

//find and display the Average of all document size
void averagedocsize()
{   
    struct documents Queue;

    if (front == NULL) 
    {
        printf("\n ooops List is Empty\n");
    }
    else
    {
        struct documents *tempp = (struct documents*)malloc(sizeof(struct 
           documents));
        int count = 0;
        tempp = front;
        Queue = tempp->Queue;
        while (tempp != NULL) 
        {
            if(strcmp(Queue.docsize, docsize) == 0) {
                sum=0;
                while (count<=rearindex)
                {
                    sum = sum + docsize;
                    average =rearindex;
                }

                count++;
            }
            tempp = tempp->next;
            if (tempp == NULL) {
                printf("Average Document Size is : %d\n\n", average);
                break;
            }
            Queue = tempp->;
        }
        free(tempp);
    }
}
1
Queue is not declared as a type, so Queue ** [or Queue *] is invalid. And, your typedef declares the struct name Book but not a type of Book (i.e. it's legal but a bit malformed). Try: typedef struct Book { what_you_already_have } Book; Then, do void Enqueue(Book **rear, Book **front, Book *en). When you did struct Book Queue;, Queue is merely a global instance of type struct Book--it does not declare a type of Queue. - Craig Estey
When I compile this code I get a bunch of errors, but none of them is the error you say you got. Please read and follow the instructions for producing a minimal, complete, verifiable example program. - zwol
Please don't shout. - Dave Newton
While the code is certainly incorrect, it is hard to see how it would yield [error] variable or field 'Enqueue' declared void - it seems likely that this is not the code that generated the error. Copy & paste your code and the errors carefully - do not remove content - for example the error message will include information such as the line number - don't remove that, and ensure the code you post includes that line. Also your title bares no relation to the body text - the title is much broader (too broad), and the body very specific (about an error message). - Clifford
From a style point of view, the name Queue is too generic to refer to specifically a queue of books, and the type is not a queue, but an element of a queue. typedef Book* BookQueue ; perhaps makes more sense, then the Enqueue parameters would have type BookQueue*. - Clifford

1 Answers

0
votes

You have defined a variable Queue rather than a type, and the typedef is incomplete :

typedef struct Book
{
    int bID;
    char bName;
    char FolderName;
    struct Book * next
    struct Book * next
} Queue ;

void Enqueue(Queue ** rear, Queue ** front, Queue en) ;