Previous declaration of ___ was here

Reply

Join Date: Sep 2009
Posts: 7
Reputation: TGeorge824 is an unknown quantity at this point 
Solved Threads: 0
TGeorge824 TGeorge824 is offline Offline
Newbie Poster

Previous declaration of ___ was here

 
0
  #1
Sep 17th, 2009
Hi, for an assignment I have to do, we have to made a Stack and Queue, and read data from a file and add to queue and push onto the stack. Well, I made an array implementation of a stack that works fine, but the array implementation of the Queue is really giving me problems. I keep getting, especially surrounding my remove subroutine, a "error: conflicting types for remove" and "previous declaration of 'remove' was here" errors.

Any help would be appreciated.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "queueADT.h"
  4.  
  5. #define QUEUE_SIZE 100
  6.  
  7. struct queue_type {
  8. int contents[QUEUE_SIZE];
  9. int cursor;
  10. int size;
  11. };
  12.  
  13. static void terminate(char *message)
  14. {
  15. printf("%s\n", message);
  16. exit(EXIT_FAILURE);
  17. }
  18.  
  19. Queue create()
  20. {
  21. Queue q;
  22. q = malloc(sizeof(struct queue_type));
  23. if(q == NULL)
  24. terminate("Error in create: Queue could not be created.");
  25. q->cursor = 0;
  26. q->size = 0; //Size is zero because no elements have been added yet
  27.  
  28. return q;
  29. }
  30.  
  31. void destroy(Queue q)
  32. {
  33. free(q);
  34. }
  35.  
  36. bool is_empty(Queue q)
  37. {
  38. return q->size == 0;
  39. }
  40.  
  41. bool is_full(Queue q)
  42. {
  43. return q->size == QUEUE_SIZE;
  44. }
  45.  
  46. void add(Queue q, int i) //Adds an element to the end of the queue
  47. {
  48. int last = get_last(q); //finds last occupied spot in the queue
  49.  
  50. while(q->cursor<=QUEUE_SIZE) //Makes sure you dont go out of bounds
  51. q->cursor++;
  52. q->contents[q->cursor]=i;
  53. q->size++;
  54. }
  55.  
  56. int remove(Queue q) //Removes the first element from the queue
  57. {
  58. get_first(q); //MAKE SURE IT MOVES THE CURSOR!!!!!
  59. int removed = q->contents[0]; //Saves the item to return it
  60.  
  61.  
  62.  
  63. q->cursor++; //Prepares to move the element
  64. while(q->cursor<q->size) //Should shift each element one to the left without
  65. { //going out of bounds
  66. q->contents[q->cursor] = q->contents[q->cursor-1];
  67. q->cursor++;
  68. }
  69. q->size--;
  70.  
  71. return removed;
  72. }
  73.  
  74. void get_first(Queue q) //Moves the cursor to zero since you already know
  75. { //where the first item is
  76. q->cursor=0;
  77. }
  78.  
  79. int get_next(Queue q) //returns index of the next item in the queue and moves the cursor there
  80. {
  81. q->cursor++;
  82. return q->cursor;
  83. }
  84.  
  85. int get_last(Queue q) //finds the last element, returns its index, and moves the cursor there
  86. {
  87. q->cursor = q->size-1;
  88. return q->cursor;
  89. }
  90.  
  91. int main()
  92. {
  93. Queue q1;
  94.  
  95. q1 = create();
  96.  
  97. /* add(q1, 10);
  98. add(q1, 20);
  99.  
  100. remove(q1); */
  101.  
  102. return 0;
  103. }

I dont know how to tag my header properly, the code tags arent working... so I guess Ill just paste it in bold letters... sorry

/*queueADT.h*/

#ifndef QUEUEADT_H
#define QUEUEADT_H

#include <stdbool.h>

typedef struct queue_type *Queue;

Queue create();
void destroy(Queue q);
bool is_empty(Queue q);
bool is_full(Queue q);
void add(Queue q, int i);
int remove(Queue q);
void get_first(Queue q);
int get_next(Queue q);
int get_last(Queue q);


#endif
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Previous declaration of ___ was here

 
0
  #2
Sep 17th, 2009
> typedef struct queue_type *Queue;
This should come AFTER your actual struct declaration.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,342
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Previous declaration of ___ was here

 
1
  #3
Sep 17th, 2009
remove is the name of a standard library function, choose another name.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC