// Declaring the structure:
typedef struct stEntry{
char *lexeme;
int line;
int idcount;
} SYMBOLTABLEENTRY;
// Creating the array of structures:
SYMBOLTABLEENTRY *symbolTable[200];
// The function to create a new struct for the array
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
{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:
void printEntries()
{
for(i = 0; i < tol; i++)
{
sprintf(symbolTable[i].line,"%d:");
printf("", symbolTable[i].lexeme);
printf("(", symbolTable[i].idcount, ")\n");
}
}

New Topic/Question
Reply




MultiQuote




|