strncpy

Dell Ellison ellisond at phobos.UUCP
Tue Jan 23 07:09:02 AEST 1990


In article <11616 at csli.Stanford.EDU>, poser at csli.Stanford.EDU (Bill Poser) writes:
> In article <000003Q at cdis-1.UUCP> tanner at cdis-1.UUCP (Dr. T. Andrews) writes:
> >Your consideration of strcpy()/strncpy() is more than a little
> >reminiscent of a man who has in hand a claw hammer and a ball peen
> >hammer, and who wishes to know why he can't pull nails with the
> >latter.
> 
> Not really. It's more like the question of why the carpentry shop
> has a ball peen hammer (used for metal working) and doesn't have
> a claw hammer. strncpy is a function evidently designed for use with
> fixed-length character buffers, not the null-terminated strings that
> are semi-standard in C. That makes one wonder why strncpy is included
> with functions that are intended for use with null-terminated strings,
> and why there is no "safe" copying function for the latter.
                                                                      
Actually, the reason why they are 'null-terminated strings' is because
they are variable in length.  If you are using strncpy then you want an
exact number of characters.  If you want n characters then you don't
want to get n+1 characters.  Besides, in C, nothing is completely safe.
I think we should all take responsability for our own strings. :-)    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    
                                                                    



More information about the Comp.lang.c mailing list