Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!brutus.cs.uiuc.edu!rpi!ptolemy0.rdrc.rpi.edu!kyriazis From: kyriazis@ptolemy0.rdrc.rpi.edu (George Kyriazis) Newsgroups: comp.lang.c Subject: Re: strncpy Message-ID: Date: 7 Jan 90 20:11:45 GMT References: <11527@csli.Stanford.EDU> <000003Q@cdis-1.UUCP> <11616@csli.Stanford.EDU> <1990Jan7.145719.15574@twwells.com> Reply-To: kyriazis@ptolemy0.rdrc.rpi.edu.UUCP (George Kyriazis) Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 21 In article <1990Jan7.145719.15574@twwells.com> bill@twwells.com (T. William Wells) writes: >In article kuro@Corp.Sun.Com writes: >: I have no opinion about philosophical correctness of the current behavior of >: strncpy() but always do: >: strncpy(to, from, n); >: to[n]=0; > >Maybe you meant "to[n - 1]=0;"? > >If the size of to is n, to[n] = 0 is illegal. > I think he means to[n] = 0. strncpy() moves at most n bytes (0 to n-1), therefore byte n is not copied. If you want to keep a string of length n you better have a char array of n+1 characters.. George Kyriazis kyriazis@turing.cs.rpi.edu kyriazis@rdrc.rpi.edu ------------------------------