typedef-ing an array

Roger House roger at everexn.uucp
Wed Jul 4 09:14:08 AEST 1990


In <78633 at srcsip.UUCP> pclark at SRC.Honeywell.COM (Peter Clark) writes:

>typedef char foo[29];

>/* a string with 28 chars, add one for the NULL byte */
>foo bar = "Hello World, this is my test";

>void
>  main()
>{
>  bar = "Silly old me";
>  printf("%s\n",bar);
>}

>The initializer works fine, but the assignment inside main() doesn't.

foo is of type "array of char".  The string "Silly old me" is of type "pointer
to char".  These are two different things.  In C you cannot assign a value to
an array by using the assignment operator "=".  The proper way to do what you
are trying to do in the first statement of main is this:

		strcpy(bar, "Silly old me");

							Roger House



More information about the Comp.lang.c mailing list