I'm going crazy trying to figure out this error message that has no obvious connection to reality/my code. I've been searching on here and come to one conclusion: you're going to hate the pointer hidden by typedef. Sorry, it's out of my control--prof provided the code that way. I'm editing the code as specified in the problem. I'm popping full nodes to avoid malloc calls on each push function and storing them in a secondary stack. The MakeEmptyS function initializes a Stack with INITIAL_SIZE nodes. GrowEmptyS adds more nodes to the Stack of empty nodes
stack.c has the following function:
void
MakeEmptyS( Stack S )
{
PtrToNode tmp;
if ( S == NULL )
Error( "Must use CreateStack first" );
else
{
GrowEmptyS( S, INITIAL_SIZE);
while (!IsEmptyS( S) )
{
tmp = TopopNode( S );
PushEmpty( S, tmp);
}
}
}
I get this error: "Stack.c:53:22: error: expected expression before '=' token", where line 53 is GrowEmptyS( S, INITIAL_SIZE );
For reference, here is the Grow function:
void
GrowEmptyS( Stack S, int NumToAdd )
{
int i;
PtrToNode TmpCell;
for( i = 0; i < NumToAdd; i++ )
{
TmpCell = malloc( sizeof(struct Node));
if ( TmpCell == NULL )
FatalError( "Out of Space!!!");
else
PushEmpty(S,TmpCell);
}
}
A1: The error means that the compiler didn't expect you to assign an array to a scalar. When you specify rob_leftcolor[3] = {1.0, 0.0, 0.0}; , you tell compiler, I want you to assign vector of values {1.0, 0.0, 0.0} to 4th element of array rob_leftcolor (counting starts from 0 - 0, 1, 2, 3).
expected primary-expression before ')' token. Sometimes this happens when the variable passed into a function isn't the type the function expected. Make sure variables are defined in the correct scope and that the types match the definition.
Expected expression. This error is produced whenever the compiler is expecting an expression on the line where the error occurred. In the following example, the trailing comma in the initializer indicates to the compiler that another expression will follow.
I may be wrong but probably you defined
#define INITIAL_SIZE = 1024
for example.
You should remove the =.
The correct definition would be
#define INITIAL_SIZE 1024
As an advice, function parameters should start with lower case, not upper case :)
void GrowEmptyS(Stack stack, int numToAdd)
is easier to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With