Path: utzoo!utgpu!watserv1!watmath!att!rutgers!usc!zaphod.mps.ohio-state.edu!rpi!leah!bingvaxu!vu0310 From: vu0310@bingvaxu.cc.binghamton.edu (R. Kym Horsell) Newsgroups: comp.lang.c Subject: Re: stupid compilers Message-ID: <3924@bingvaxu.cc.binghamton.edu> Date: 31 Aug 90 20:31:31 GMT References: <163@prodix.liu.se> Reply-To: vu0310@bingvaxu.cc.binghamton.edu.cc.binghamton.edu (R. Kym Horsell) Organization: SUNY Binghamton, NY Lines: 31 In article <163@prodix.liu.se> martin@prodix.liu.se (Martin Wendel) writes: \\\ > #include > #include > 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