| | |
Previous declaration of ___ was here
![]() |
•
•
Join Date: Sep 2009
Posts: 7
Reputation:
Solved Threads: 0
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.
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
Any help would be appreciated.
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> #include "queueADT.h" #define QUEUE_SIZE 100 struct queue_type { int contents[QUEUE_SIZE]; int cursor; int size; }; static void terminate(char *message) { printf("%s\n", message); exit(EXIT_FAILURE); } Queue create() { Queue q; q = malloc(sizeof(struct queue_type)); if(q == NULL) terminate("Error in create: Queue could not be created."); q->cursor = 0; q->size = 0; //Size is zero because no elements have been added yet return q; } void destroy(Queue q) { free(q); } bool is_empty(Queue q) { return q->size == 0; } bool is_full(Queue q) { return q->size == QUEUE_SIZE; } void add(Queue q, int i) //Adds an element to the end of the queue { int last = get_last(q); //finds last occupied spot in the queue while(q->cursor<=QUEUE_SIZE) //Makes sure you dont go out of bounds q->cursor++; q->contents[q->cursor]=i; q->size++; } int remove(Queue q) //Removes the first element from the queue { get_first(q); //MAKE SURE IT MOVES THE CURSOR!!!!! int removed = q->contents[0]; //Saves the item to return it q->cursor++; //Prepares to move the element while(q->cursor<q->size) //Should shift each element one to the left without { //going out of bounds q->contents[q->cursor] = q->contents[q->cursor-1]; q->cursor++; } q->size--; return removed; } void get_first(Queue q) //Moves the cursor to zero since you already know { //where the first item is q->cursor=0; } int get_next(Queue q) //returns index of the next item in the queue and moves the cursor there { q->cursor++; return q->cursor; } int get_last(Queue q) //finds the last element, returns its index, and moves the cursor there { q->cursor = q->size-1; return q->cursor; } int main() { Queue q1; q1 = create(); /* add(q1, 10); add(q1, 20); remove(q1); */ return 0; }
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
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
![]() |
Similar Threads
- mysterious segmentation fault (C)
- Header files, C++ vs C compiler question (C++)
- Modem Help (*nix Hardware Configuration)
- GDI+ with Win32 API Dev-C++ (C++)
- Invalid conversions while using other people's software (C++)
- C Program help - Conway's Life - Stumped by some errors. (C)
- help with some error codes please. (C)
- Counting specific characters in a string (C)
- Cant compile on Linux (IT Professionals' Lounge)
Other Threads in the C Forum
- Previous Thread: Pointers and nested structures
- Next Thread: Convert Decimal to Radix
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char character cm convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hardware highest homework i/o ide inches intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h windowsapi






