tags:

views:

70

answers:

4

Hi, I'm looking to initialize a global array of stucts in C within the header file however it keeps complaining when compiling. Here's my struct

typedef struct
{
 char input[100][100];
 int count;
 char name;
}INPUT;

extern INPUT[] global;

Thanks

+1  A: 

In your header, declare an extern pointer to the array e.g.

extern INPUT *global;

In one of the bodies, declare the actual storage:

INPUT global_[N], *global = global_;
Will
+1  A: 
  • You can't initialise it in the header file, do it in the C file.
  • Use extern if you want to access this global array in some other C file.
Reno
A: 

I had to guess at what you want, I hope this about it:

typedef struct {
  char input[100][100];
  int count;
  char name;
} INPUT;

INPUT global[] = {
  { {'x', 'y'}, /* count: */ 1, /* char */ 'x' },
  { {"how now", 'y'}, /* count: */ 1, /* char */ 'x' },
  { {"brown cow", 'y'}, /* count: */ 1, /* char */ 'x' },
  { {"more", " stuff"}, /* count: */ 1, /* char */ 'x' },
  { {{'x', 'y'}, {'a', 'b'}}, /* count: */ 1, /* char */ 'x' },
};

Build with cc -Wall -Wno-missing-braces -c ...

DigitalRoss
A: 

Not sure about this, but can you try by giving the size of the array?
extern INPUT[100] global;

Manoj R