![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 2
| stack and array.. Code:
hi guys.
can anybody check why my code got error..
/* Declaration of Stack data structure */
#define MAXSTK 10;
typedef int ELEMENT;
typedef enum bool { FALSE, TRUE } BOOL;
typedef struct node
{
int top;
ELEMENT data [MAXSTK]; first error "array bound missing"
} STK;
/* Declaration of function prototypes */
void CreateStk (STK *t);
BOOL EmptyStk (STK *t);
BOOL FullStk (STK *t);
void InsertStk (ELEMENT item, STK *t);
void RemoveStk (ELEMENT *item, STK *t);
main ( )
{
int counter, number, temp;
STK odd, even;
/* Create even and odd stacks */
CreateStk(&odd);
CreateStk(&even);
/* Read data & insert into the related stack */
for (counter = 1; counter <= 10; counter ++)
{
printf("\nInput number : ");
scanf("\n%d, &number); second also not detect number as a variable..
if (number%2 == 0)
InsertStk(number, &even);
else
InsertStk(number, &odd);
}
/* Print contents of odd stack */
printf("\nPrinting Odd Numbers : ");
while (!EmptyStk (&odd))
{
removeStk (&temp, &odd);
printf("%d ", temp);
}
/* Print contents of even stack */
printf("\nPrinting Even Numbers : ");
while (!EmptyStk (&even))
{
removeStk (&temp, &even);
printf("%d ", temp);
}
/*Create empty stack*/
void createStk (STK *t)
{
(return (BOOL)(t->top<=10))
t->top=0;
}
/*Check Empty Stack*/
BOOL emptyStk (STK *t)
{
(return (BOOL)(t->top<=10))
}
/*Check Full Stack*/
BOOL fullStk (STK *t)
{
(return (BOOL) (t->top >= MAXSTK));
}
/*If t is full */
void insertStk (ELEMENTTYPE item, STK *t);
{
if (fullStk(t))
printf(“\nStack Full \n”);
else
{
t->element[t->top] = item;
t->top++;
}
}
/* Remove an item from a stack t or display an error message
if t is empty */
void removeStk (ELEMENTTYPE *item, STK *t);
{
if (emptyStk(t))
printf(“\nStack Empty \n”);
else
{
t->top--;
*item = t->element[t->top];
}
}
|
| zackysue is offline | |
| | #2 |
| Algorithm Dissector Join Date: Dec 2005 Location: New Zealand
Posts: 2,476
| Compile-time error or run-time error? Always post the errors you are getting. Many of us are not going to compile this ourselves either.
__________________ My homepage Advice: Take only as directed - If symptoms persist, please see your debugger |
| iMalc is offline | |
| | #3 |
| Registered User Join Date: Nov 2009
Posts: 2
| sorry that.. during compiling i found error ... "array bound missing" |
| zackysue is offline | |
| | #4 | |
| Registered User Join Date: Nov 2009
Posts: 1
| Quote:
| |
| x86_64 is offline | |
| | #5 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,262
| Whitespace doesn't matter: Code: int foo [ SIZE ] = { 0 } ;
int bar[SIZE]={0};
Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #6 |
| Registered User Join Date: Sep 2006
Posts: 2,517
| How about a nice int main() with a return at the end of main, and showing your include files? Odd to see a #define, but no included headers. OK, you need to remove the semi-colon from the end of the #define line of code. You have several other errors: 1) An unterminated string in the scanf() 2) You are creating functions, inside main() - put them outside main, instead. Like this one: Code: /*Create empty stack*/
void createStk (STK *t)
{
(return (BOOL)(t->top<=10))
t->top=0;
}
Last edited by Adak; 11-05-2009 at 08:34 AM. |
| Adak is offline | |
| | #7 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| Yeah, it is also rather odd that there is a semi-colon after the 10 at the #define.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Vertical Scroller laser cannon problem | Swarvy | Game Programming | 5 | 05-02-2009 06:30 PM |
| Stack Overflow when declaring array | ejohns85 | C++ Programming | 3 | 04-03-2009 05:00 AM |
| Fixing my program | Mcwaffle | C Programming | 5 | 11-05-2008 03:55 AM |
| stack and pointer problem | ramaadhitia | C Programming | 2 | 09-11-2006 11:41 PM |
| Question about a stack using array of pointers | Ricochet | C++ Programming | 6 | 11-17-2003 10:12 PM |