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.

Recommended Answers

All 3 Replies

Sorry, here are the first 4 lines of match.c

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "match.h"

Executable statements have to be inside of a function. These are the executable statements in your header file.

word_list->input = "a";
word_list[0].output = "b";

(word_list+1)->input = "c";
(word_list[1]).output = "d";

Oh of course, thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.