C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-05-2009, 12:59 AM   #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   Reply With Quote
Old 11-05-2009, 01:06 AM   #2
Algorithm Dissector
 
iMalc's Avatar
 
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   Reply With Quote
Old 11-05-2009, 02:57 AM   #3
Registered User
 
Join Date: Nov 2009
Posts: 2
sorry that..
during compiling i found error ...

"array bound missing"
zackysue is offline   Reply With Quote
Old 11-05-2009, 03:04 AM   #4
Registered User
 
Join Date: Nov 2009
Posts: 1
Quote:
ELEMENT data [MAXSTK]; first error "array bound missing"
Remove the white space between data[MAXSTK]
x86_64 is offline   Reply With Quote
Old 11-05-2009, 05:50 AM   #5
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,262
Quote:
Originally Posted by x86_64 View Post
Remove the white space between data[MAXSTK]
Whitespace doesn't matter:
Code:
int foo [ SIZE ] = { 0 } ;
int bar[SIZE]={0};
The two lines are the same thing (except for variable name).


Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 11-05-2009, 08:12 AM   #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   Reply With Quote
Old 11-05-2009, 08:19 AM   #7
C++ Witch
 
laserlight's Avatar
 
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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 03:46 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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