Struct Not Being Reconized

This is a discussion on Struct Not Being Reconized within the C Programming forums, part of the General Programming Boards category; I am writing a program for a data structures class in which we are using pre-written functions from the teacher ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    Struct Not Being Reconized

    I am writing a program for a data structures class in which we are using pre-written functions from the teacher (and I use that term loosely) and we are to basicly build the main driver loop. I have run into a problem in which the struct does not seem to be acting as it should. I get a lot of errors and warnings when trying to complile about it not seeing elements of the structure itself.

    Can someone take a look at this and see if there are any glaring mistakes...(some of the last function is not written yet but that is the least of my issue).

    Code:
    //***************************************************************************
    
    #include <stdio.h>
    #include <conio.h>
    
    #define TRUE 1
    #define FALSE 0
    #define MAXQUEUE 5
    
    
    /* The Queue is declared as a Structure with three members:
    	item, front and back. Front & back keeps track of the index values of
    	Queue for circular reference and array items is used for storage of
    	the items */
    
    struct stack
    {
    	 int front,rear;
    	 int items [MAXQUEUE];
    };
    
    /* Prototypes */
    
    void initQ   (struct queue *pq);
    int  emptyQ  (struct queue *pq);
    void insertQ (struct queue *pq, int x);
    int  removeQ (struct queue *pq);
    int  EvenOdd (int x);
    int  flushQ  (int temp[]);
    
    
    /*  Main Program */
    //***************************************************************************
    
    int main (void)
    {
    
    	char response;              // for driving main program loop
    	int numb,front,rear,items;  // for holding numbers
    
    	int temp[MAXQUEUE];			 // holds items for final print
    	struct stack pq;             // Stack 'pq' used to store numbers
    
    	initQ (&pq);             // Call to initialize the stack
    
    
    	clrscr();                   // Clear the screen
    
    	// ask to start the program... if '!y' exit
    	fflush (stdin);
    	printf("\n\n\nDo you want to enter items into the Queue? (y/n) > ");
    	scanf("%c", &response);
    
    	while (response == 'y')
    	{
    
    		clrscr();                // Clear the screen
    		printf("\nEnter a number...");
    		printf("\n **NOTE**  whole numbers only (no decimal points) ");
    
    		fflush (stdin);
    		scanf("%d",numb);
    
    		//Evaluate Inputed Number for Odd or Even and Process
    
    		items=EvenOdd(numb);
    
    		if (items < 0)
    		{
    			insertQ(&pq,items);
    			printf("\n\n\t %d Inserted",items);
    		}
    		else
    		{
    
    			items = removeQ (&pq);    //take front number from the queue
    			if (items < 0)
    				printf("\n\n\t\t Queue is Empty - No Deletion Possible.");
    
    			printf("\n %d Deleted",items);
    		}
    
    		fflush (stdin);
    		printf("\n\n\n\t Do you want to enter another number? (y/n) > ");
    		scanf("%c", &response);
    
    	}
    
    	numb=flushQ(&temp);
    	if (numb < 0)
    	{
    		clrscr();
    		printf("Nothing Left in the Queue");
    	}
    	else
    	{
    		clrscr();
    		printf("\n\t\t Number of Items left in the Queue is %d",items);
    		printf("\n\t\t Front Item is %d",front);
    		printf("\n\t\t Back Item is %d",rear);
    	}
    
    	printf("\n\n\n PROGRAM TERMINATED");
    	return 1;
    
    
    }
    
    
    // FUNCTION CALLS
    /***************************************************************************/
    
    
    /* This function initializes the Queue   */
    
    void initQ (struct queue *pq)
    {
    	 pq->front = MAXQUEUE-1;
    	 pq->rear = MAXQUEUE -1;
    
    	 return;
    }
    
    /* This function checks if the queue is empty   */
    
    int emptyQ (struct queue *pq)
    {
    	  if  (pq->front == pq->rear)
    			return (TRUE);
    	  else
    			return (FALSE);
    }
    
    /* This function will insert items into the queue   */
    
    void insertQ (struct queue *pq, int x)
    {
    	 int temp;
    
    	 temp = pq->rear ;
    
    	 if (pq->rear == MAXQUEUE-1)
    		  pq->rear =  0;
    	 else
    		  (pq->rear)++;
    
    	  /*  Chech for overflow  */
    
    	  if (pq->rear == pq->front)
    	  {
    		  printf("%d Could not be inserted-Queue is Full\n",x);
    		  pq->rear = temp;
    	  }
    	  else
    		  pq->items[pq->rear] = x;
    
    	  return;
    }
    
    
    
    /* This function  will remove items from the queue
    		(If queue is empty it returns 0,
    			 else it removes the front item and returns it's value) */
    
    int removeQ (struct queue *pq)
    {
    
    
    	 if (empty(&pq) == TRUE )
    	 {
    			return 0;
    	 }
    	 else
    		if (pq->front == MAXQUEUE-1)
    			pq->front = 0;
    		else
    			(pq->front)++;
    		return(pq->items[pq->front]);
    
    }
    
    
    /* This function checks if number is Odd or Even If odd return -1 else
    		return number inputed   */
    
    int EvenOdd (int x)
    {
    	 if (x%2>0)
    	 {           // odd if there is a remainder
    		return -1;       // return odd
    	 }
    	 return x;          // return number given
    
    }
    
    /* This function checks if number is Odd or Even If odd return -1 else
    		return number inputed   */
    
    int flushQ (int temp[])
    {
    
    	int x;
    
    	x=remove(&pq);			// remove front number and stores it
    	if (x < 0)
    
    		return -1;
    
    	else
    	{
    		front = x;
    		items++;
    	}
    
    	// may drive this with a for loop
    	rear=remove(&pq);
    	if (rear<0)  // stack is empty
    	{
    
    		printf("\n\n The Total number of items in the queue are... ",items);
    		printf("%d, ",front);
    		return 1;
    	}
    	return 2;
    
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,698
    Code:
    void initQ   (struct queue *pq);
    int  emptyQ  (struct queue *pq);
    void insertQ (struct queue *pq, int x);
    int  removeQ (struct queue *pq);
    Where is the struct queue defined? Should struct stack be struct queue?

    Jim

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    Thumbs up

    Sometimes it takes a second pair of eyes. Thanks, that cleared most of the issues. Still getting some errors in flushQ but I was just beginning to filter through it when I decided to compile to work through it.

    That was only two hours worth of beating my head against the desk for a 15 minute wait on help...

    Where would I be without Cprogramming.com...(still banging my head against the desk!)

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,698
    When you look at your error messages the line number where the error occurred usually helps find the error.

    Jim

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    3
    yes I know and I kept looking right past the obvious!

    With prcatice you begin to reconize these types of errors.

    If you don't ever make a mistake, you have either learned nothing or do not want to learn anything new!

    Thanks for all the positive feedback. We can call this one closed for now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. casting struct to struct
    By klmdb in forum C Programming
    Replies: 6
    Last Post: 08-14-2010, 02:29 PM
  2. I'm donating my vector lib.
    By User Name: in forum C Programming
    Replies: 23
    Last Post: 06-24-2010, 06:10 PM
  3. help with structs and malloc!
    By coni in forum C Programming
    Replies: 20
    Last Post: 09-14-2009, 05:38 PM
  4. Replies: 1
    Last Post: 12-03-2008, 02:10 AM
  5. Replies: 10
    Last Post: 05-18-2006, 11:23 PM

Tags for this Thread


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