C problem, left of '->' must point to class/struct/union/generic type ??
Posted
by Patrick
on Stack Overflow
See other posts from Stack Overflow
or by Patrick
Published on 2010-05-28T22:52:29Z
Indexed on
2010/05/28
23:02 UTC
Read the original article
Hit count: 163
Hello!
Trying to understand why this doesn't work. I keep getting the following errors:
left of '->nextNode' must point to class/struct/union/generic type
(Also all the lines with a -> in the function new_math_struct)
Header file
#ifndef MSTRUCT_H
#define MSTRUCT_H
#define PLUS 0
#define MINUS 1
#define DIVIDE 2
#define MULTIPLY 3
#define NUMBER 4
typedef struct math_struct
{
int type_of_value;
int value;
int sum;
int is_used;
struct math_struct* nextNode;
} ;
typedef struct math_struct* math_struct_ptr;
#endif
C file
int get_input(math_struct_ptr* startNode)
{
/* character, input by the user */
char input_ch;
char* input_ptr;
math_struct_ptr* ptr;
math_struct_ptr* previousNode;
input_ptr = &input_ch;
previousNode = startNode;
/* as long as input is not ok */
while (1)
{
input_ch = get_input_character();
if (input_ch == ',') // Carrage return
return 1;
else if (input_ch == '.') // Illegal character
return 0;
if (input_ch == '+')
ptr = new_math_struct(PLUS, 0);
else if (input_ch == '-')
ptr = new_math_struct(MINUS, 0);
else if (input_ch == '/')
ptr = new_math_struct(DIVIDE, 0);
else if (input_ch == '*')
ptr = new_math_struct(MULTIPLY, 0);
else
ptr = new_math_struct(NUMBER, atoi(input_ptr));
if (startNode == NULL)
{
startNode = previousNode = ptr;
}
else
{
previousNode->nextNode = ptr;
previousNode = ptr;
}
}
return 0;
}
math_struct_ptr* new_math_struct(int symbol, int value)
{
math_struct_ptr* ptr;
ptr = (math_struct_ptr*)malloc(sizeof(math_struct_ptr));
ptr->type_of_value = symbol;
ptr->value = value;
ptr->sum = 0;
ptr->is_used = 0;
return ptr;
}
char get_input_character()
{
/* character, input by the user */
char input_ch;
/* get the character */
scanf("%c", &input_ch);
if (input_ch == '+' || input_ch == '-' || input_ch == '*' || input_ch == '/' || input_ch == ')')
return input_ch; // A special character
else if (input_ch == '\n')
return ','; // A carrage return
else if (input_ch < '0' || input_ch > '9')
return '.'; // Not a number
else
return input_ch; // Number
}
The header for the C file just contains a reference to the struct header and the definitions of the functions. Language C.
© Stack Overflow or respective owner