Question:
Why wont this work? C programming?
Eun
2011-03-29 12:09:16 UTC
include

#define MAX_QUEUE_CAPACITY 10

/* List of valid shapes which could be displayed in the shapes cloud */
typedef enum shapes { rectangle, square, ellipse, circle } Shapes;

/* Each item in the queue will be a shape with a count of the number of times
the shape appears in the input data. */
typedef struct queueItem
{
Shapes tagShape;
int tagCounter;
} NameWeight;

/* The queue uses an array of fixed size to store the items. */
typedef struct queue
{
int currentQueueSize;
int queueFrontIndex;
int queueRearIndex;
NameWeight currentQueueItems[ MAX_QUEUE_CAPACITY ];
} Queue;

/* Queue currently in use by program */
Queue shapesCloud;

/* Key queue operations */
void enqueue( QueueItem ); /* Adds an item to the rear of the queue */
NameWeight dequeue(); /* Removes an item from the front of the queue */


int main( void )
{

//write code here

//need 2 que items, 1 input that loops, 1 to store the output of q.

int counter;

NameWeight person;


for (counter = 0, counter < MAX_QUEUE_CAPACITY, counter++)
{

scanf( "%s", &person.tagShape);
scanf( "%f", &person.tagCounter);

enqueue (person);
}

printf("The queue is...");

for (counter = 0, counter < MAX_QUEUE_CAPACITY, counter++)
{

printf( "%s \n", shapesCloud.currentQueueItems);
}

//need for loop 2 scan input, scan AND q it

//after the loop it needs 2 be de qued, deque = dequeue()

//print result

}


void enqueue( QueueItem item )
{
/* Do not add if the queue is full */
if ( shapesCloud.currentQueueSize >= MAX_QUEUE_CAPACITY ) return;

/* Add new item and increment queue size counter */
shapesCloud.currentQueueItems[ shapesCloud.queueRearIndex ] = item;
shapesCloud.currentQueueSize++;

/* Move the rear index to the right and wraparound if end of the array is reached */
shapesCloud.queueRearIndex++;
if ( shapesCloud.queueRearIndex >= MAX_QUEUE_CAPACITY )
shapesCloud.queueRearIndex = shapesCloud.queueRearIndex - MAX_QUEUE_CAPACITY;
}

QueueItem dequeue()
{
NameWeight item = { rectangle, 0 };

/* Nothing to return if the queue is empty */
if ( shapesCloud.currentQueueSize < 1 ) return item;

/* Return the item at the front position and decrement the queue size counter */
item = shapesCloud.currentQueueItems[ shapesCloud.queueFrontIndex ];
shapesCloud.currentQueueSize--;

/* Move the front index to the right and wraparound if the end of the array is reached */
shapesCloud.queueFrontIndex++;
if ( shapesCloud.queueFrontIndex >= MAX_QUEUE_CAPACITY )
shapesCloud.queueFrontIndex = shapesCloud.queueFrontIndex - MAX_QUEUE_CAPACITY;

/* Return the found item */
return item;
}

input = gary 10 bo 4 heknm 4 kgj 1 jyugfo 78 jkhf 23 kjhv 11

Error: : In function 'main':
Line 36 ERROR: expected expression before '/' token
compilation terminated due to -Wfatal-errors.
Five answers:
The Phlebob
2011-03-29 12:13:59 UTC
// comment notation is C++. Unless your C compiler accepts it, use the /* --- */ comment notation.



Hope that helps.
anonymous
2011-03-29 19:16:16 UTC
Your for loops, you are using commas between your expressions when you should be using semicolons



e.g.



for(x=0;x>=10;x++)

{

//Do some crap 10 times! YAY!

}
Joe
2011-03-29 19:14:43 UTC
"Plain Vanilla" C language doesn't accept the "//" comment construction. Stick with



/* comment */



Also: in your first line, "include" should be "#include". (But that's probably a cut & paste error.)
eli porter
2011-03-29 19:12:03 UTC
in the for loop its not commas for separators its semicolons.
anonymous
2011-03-29 19:16:38 UTC
You cant use // to comment in C


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...