I want to define a struct in a C header file, which contains several strings. For example, 3 files are listed below and struct fileList is defined.
#include <stdio.h>
#define FILE1 "/data/file1"
#define FILE2 "/data/file2"
#define FILE3 "/data/file3"
typedef struct fileList{
FILE1;
FILE2;
FILE3;
}fileList;
int main()
{
fileList fl;
printf("Hello world! %s\n", fl.FILE1);
}
But when I run it, I got bellow errors. Why? And do you have better solution? Thanks!
gcc test.c
test.c:3:15: error: expected specifier-qualifier-list before string constant
#define FILE1 "/data/file1"
^
test.c:8:5: note: in expansion of macro ‘FILE1’
FILE1;
^
test.c: In function ‘main’:
test.c:3:15: error: expected identifier before string constant
#define FILE1 "/data/file1"
^
test.c:16:36: note: in expansion of macro ‘FILE1’
printf("Hello world! %s\n", fl.FILE1);