stupid compilers

R. Kym Horsell vu0310 at bingvaxu.cc.binghamton.edu
Sat Sep 1 06:31:31 AEST 1990


In article <163 at prodix.liu.se> martin at prodix.liu.se (Martin Wendel) writes:
\\\
>           #include <stdio.h>
>           #include <strings.h>
>           main()
>           {
>             char line[];
>             char *tmp = "1234";
>             strcpy(line, tmp);
>             printf("%s\n", line);
>           }
\\\

Strictly speaking neither of these programs is ok. In the first one
you have allocated how many bytes for ``line''? (In is supposed
to be an array). In the second, which uses a char * instead of
an array, how many bytes have you allocated to store them?

None.

If you try:
		char line[5];

things will look a bit better -- remember to allocate 1 extra
byte to store that pesky null at the end of every (normal) C
string. Alternatively,
		char *line;
		line = malloc(5);
should also work.

-Kym Horsell



More information about the Comp.lang.c mailing list