Message-Id: <199710240221.MAA29326@rabble.uow.edu.au> Subject: strncpy question To: djgpp AT delorie DOT com (DJGPP) Date: Fri, 24 Oct 1997 12:21:52 +1000 (EST) From: Brett Porter MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk Here is something strange I have encountered using DJGPP... I use this code in C++, where fName is a char* and aName is const char* fName = new char[strlen(aName)+1]; strncpy( fName, aName, 74 ); I don't want anymore than 74 characters to be displayed when I cprintf( fName ), because it goes to the text mode screen, so I do this and also put a zero at fName[74] (if the string length is that long) It started to overwrite other memory. I realise what I had done here was bad coding, and I've fixed it up, but I was curious what was going on here. IS the definition of strncpy in DJGPP to zero out up to the limit specified, or does it stop at the NULL character? I thought it was the latter but this example would seem to indicate otherwise. No urgency in replying, I'm just curious Brett -- "Who here believes in telekenesis? Raise MY hand!" -- Brett Porter bporter AT rabble DOT uow DOT edu DOT au http://www.geocities.com/CollegePark/Union/3596 Humour, Programming, and more.