Hey guys, so what I'm trying to do is print each member of a struct from every struct in an array. When I try to use the following code, I get an error saying "error request for member 'line' in something not a structure or union. It says this for all members of the structure. Let me know if you guys can see anything wrong:
// Declaring the structure:
Code:
typedef struct stEntry{
char *lexeme;
int line;
int idcount;
} SYMBOLTABLEENTRY;
// Creating the array of structures:
Code:
SYMBOLTABLEENTRY *symbolTable[200];
// The function to create a new struct for the array
Code:
SYMBOLTABLEENTRY *createEntry(char* yytext, int ln, int id)
{
SYMBOLTABLEENTRY *temp_st;
temp_st = (SYMBOLTABLEENTRY *)malloc(sizeof(SYMBOLTABLEENTRY));
temp_st->lexeme = strcpy(test, yytext);
temp_st->line = ln;
temp_st->idcount = id;
return temp_st;
}
// When it finds an ID token, it adds a struct to the array
Code:
{ID} {printf("found ID token"); symbolTable[tol++] = createEntry(yytext, lineno, idcount++);}
// Where I'm having the problems, trying to print all elements of the struct array:
Code:
void printEntries()
{
for(i = 0; i < tol; i++)
{
sprintf(symbolTable[i].line,"%d:");
printf("", symbolTable[i].lexeme);
printf("(", symbolTable[i].idcount, ")\n");
}
}