I was writing a program and wanted to write a struct that's used to match an input string and print a corresponding output. However, I ran into a very unexpected problem.
This code gave me the compile error below.
#ifndef MATCH_H
#define MATCH_H
#define TOTAL_WORD_PAIRS 2
typedef struct {
char *input;
char *output;
} word_pair_t;
word_pair_t word_list[TOTAL_WORD_PAIRS];
word_list->input = "a";
word_list[0].output = "b";
(word_list+1)->input = "c";
(word_list[1]).output = "d";
#endif
In file included from match.c:4:
match.h:13: error: syntax error before '->' token
match.h:14: error: syntax error before '.' token
match.h:16: error: syntax error before '+' token
match.h:17: error: syntax error before '.' token
At first all of the ways to access the struct were the same, but I tried several possibilities to have none of them work. I am using MinGW's gcc program to compile and used this command: gcc -o match.exe match.c
Thanks in advance for any suggestions/comments.