Data Structures

This is a discussion on Data Structures within the C Programming forums, part of the General Programming Boards category; Could someone please help me with this program..why wont it compile...... #include <stdio.h> #include <stdlib.h> //#include "stdafx.h" #define MAXQUEUE 3 ...

  1. #1
    sonicsite
    Guest

    Question Data Structures

    Could someone please help me with this program..why wont it compile......


    #include <stdio.h>
    #include <stdlib.h>
    //#include "stdafx.h"

    #define MAXQUEUE 3

    typedef char QueueEntry;

    typedef struct queue{
    int count;
    int front;
    int rear;
    QueueEntry entry[MAXQUEUE];
    }Queue;

    void TraverseQueue(Queue *, QueueEntry*);
    void Append(QueueEntry, Queue *);
    void Serve(QueueEntry *, Queue *);
    void CreateQueue(Queue *);
    int QueueFull(Queue *);
    int QueueEmpty(Queue *);


    int main()
    {

    return 0;

    }


    //Create the queue
    void CreateQueue(Queue *q)
    {
    q -> count = 0;
    q -> front = 0;
    q -> rear = 0;
    }


    //Append an entry to the queue
    void Append(QueueEntry x, Queue *q)
    {
    if(QueueFull(q))
    {
    printf("Cannot append an entry to a full queue.");
    }

    else
    {
    q -> count ++;
    q -> rear = (q->rear + 1) %MAXQUEUE;
    q -> entry [q->rear] = x;
    }
    }



    void TraverseQueue(Queue *q, void (*visit) (QueueEntry))
    {
    int position;

    if(! QueueEmpty(q))
    {
    if (q ->front <= q-> rear)
    {
    for(position = q -> front; position == q -> rear; position ++);
    visit (q -> entry [position]);
    }
    else
    {
    for(position = q -> front; position == MAXQUEUE; position ++);
    visit ( q -> entry [position]);

    }
    for (position = 1; position == q -> rear; position ++)
    visit(q -> entry [position]);
    }
    }

    int QueueFull(Queue *q)
    {
    return q->count>=MAXQUEUE;
    }

    int QueueEmpty(Queue *q)
    {
    return q -> count <= 0;
    }

  2. #2
    Unregistered
    Guest
    Hmmm,

    Compiled and ran for me . . . but why are you doing :

    int main()
    {
    return 0;
    }

    That's your whole program here . . . .

  3. #3
    Unregistered
    Guest

    Question

    Yep, why are you not calling the functions in main??

    Mr. C.

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    If you have any idea at all of program flow, then you should know that program execution begins with main. In your main, it returns 0 without any processing. Do you really want to do this?
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's a good generalized data structures book?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-16-2006, 12:01 PM
  2. i need advice about data structures
    By sawer in forum C Programming
    Replies: 2
    Last Post: 04-22-2006, 03:40 AM
  3. Need some help regarding data structures
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-28-2006, 04:19 AM
  4. array of structures, data from file
    By nomi in forum C Programming
    Replies: 5
    Last Post: 01-11-2004, 12:42 PM
  5. Array Data Structures
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-27-2002, 05:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21