strcpy strncpy in c example illustration



Share

Description

The C library function char *strcpy(char *dest, const char *src) and char *strncpy(char *dest, const char *src, size_t n) are used to copy characters from src string to dest string.

strcpy() function copies the source string pointed to by src, including the terminating null character ('\0'), to the destination string pointed to by dest. The destination string dest must be large enough to hold the entire content of source string including null characters.

strncpy() function copies upto n bytes of source string src to destination string dest. If there is no null byte among the first n bytes of src, the string placed in dest will not be null-terminated. Also if length of the source string is less than n characters, remaining no of charatcers will be padded as null bytes in the destination string.



Online courses related to this article


Course description

Learn, test your C programming skills and earn certificate for software jobs



Course description

Learn firmware development theory, applications, get practical skills from online tests, projects and earn certificate for software jobs



Course description

Learn to develop embedded systems, interfacing electronic peripherals through real time projects and get required practical skills for software jobs



Course description

Learn to develop software solutions for linux environment, implement requirements through real time projects and get required practical skills for software jobs

strcpy, strncpy header file

The functions strcpy and strncpy are included in the C standard library header file string.h.



To Read Full Article

Subscribe courses or Pay Per Course & logged in



Want to contribute or ask a new article? Write and upload your article information .
Share


 Articles

 C Programming

 Linux Software

 Embedded Systems

 Python Programming

 Search Code Snippets

 Popular C search examples

 Popular C search MCQs



 Online certificate courses

 Test your skills:online tests

 C Programming

 Python Programming

 Linux Software

 Quantitative Aptitude

 Embedded System Software