[comp.lang.c] Defining array types in C

swilson%thetone@Sun.COM (Scott Wilson) (08/05/88)

>I would like to define array types in C so that I can declare variables of
>those types. The first idea that comes to mind is to use a typedef, yet the 
>syntax of typedef (and C declarations for that matter) seems to prohibit this.

This should do what you want, I think:

	typedef char name_type[20];

	typedef struct person {
		name_type name;
		int age;
	} person;

	main()
	{
		person p;

		strcpy(p.name, "Joe Schmoe");
		p.age = 12;
	}

It sounds like you are a Pascal person who is new to C.  The switching
of types and variable names confused me for a long time especially when
typedefing structs.  Often you will see people just use a struct template
without actually defining any variables, and this is also confusing.


--
Scott Wilson		arpa: swilson@sun.com
Sun Microsystems	uucp: ...!sun!swilson
Mt. View, CA