strcpy strncpy in c example illustration
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
Learn, test your C programming skills and earn certificate for software jobs
Learn firmware development theory, applications, get practical skills from online tests, projects and earn certificate for software jobs
Learn to develop embedded systems, interfacing electronic peripherals through real time projects and get required practical skills for software jobs
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 here