Difference between revisions of "Strcpy"

From Hackepedia
Jump to navigationJump to search
(New page: strcpy is part of standard libc in the c programming language. strcpy(3) can be found in the development manual pages. strncpy(name, "t", 4") --> name = "t\0\0\0" strncpy(name, "...)
 
 
Line 1: Line 1:
 
strcpy is part of standard libc in the c programming language. strcpy(3) can be found in the development [[manual]] pages.
 
strcpy is part of standard libc in the c programming language. strcpy(3) can be found in the development [[manual]] pages.
 
 
  
 
  strncpy(name, "t", 4") -->  name = "t\0\0\0"
 
  strncpy(name, "t", 4") -->  name = "t\0\0\0"

Latest revision as of 01:13, 5 September 2007

strcpy is part of standard libc in the c programming language. strcpy(3) can be found in the development manual pages.

strncpy(name, "t", 4") -->  name = "t\0\0\0"
strncpy(name, "tim", 4") --> name = "tim\0"
strncpy(name, "dave", 4)  --> name = "dave"  (note, no \0)
strncpy(name, "benjamin", 4" --> name = "benj" (still no \0)

strn* or snprintf will ensure you will never exceed SIZE, but if you are less than SIZE it pads it with \0. This will prevent buffer overflows. If you're using a BSD based system, check out strlcpy which is preferred over strncpy.