I'm having some trouble using struct which I can't seem to figure out. it seems to be following all the examples perfectly, i've tried to break it down to it's simplest block and nothing. Can somebody please tell me why this won't compile?

#include <stdio.h>

typedef struct a{
	char a[25][12]={"a", "b", "c"};
	int b[12]={10, 5,1};
};

struct test{
	char a[25][12]={"a", "b", "c", "d"};
	int b[12]={2, 1,1,3};
	int c[12]={1,1,1,2};
};

int main (){


	return 0;
}

I get this error
error C2143: syntax error : missing ';' before '='

but this error doesn't make much sense to me.

TIA.

You can't assign anything inside a structure declaration. A structure declaration just defines a type. It's like a blueprint; you're telling the compiler, "if I ask you to create a Something, this is what I want it to look like." An example of a structure declaration would be

struct Something {
    int x, y;
    double zoom;
};

When you declare an instance of a structure, you're actually using memory. Here I create a variable of type Something:

struct Something variable;

Since this is a variable, it can be initialized as you were doing above.

struct Something variable = {1, 2, 5.0};

Of course, you can always do it manually too.

struct Something variable;
variable.x = 1;
variable.y = 2;
variable.zoom = 5.0;

Just think of a structure as a new type, like int or char -- not a built-in type, but rather a type you've defined in terms of built-in types (or other structures).

commented: very straight forward and helpful, big thanks! +2

aaah!

I knew it had to be something simple like that. I'm having a terrible off day I can't believe I didn't see that.

Thanks a lot for the quick and very informative post!

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.