strncpy

Navigation:  Programming language SQC > Libraries > String manipulation >

strncpy

Previous pageReturn to chapter overviewNext page

There is a variant form of "strcpy" named "strncpy" that will copy "n" characters from the source string into the destination string,

presuming there are that many characters available in the source string.

 

char* strncpy(char *dst,char* src, int len)

 

Example:

 
void main()

{

  char s1[10], 

       s2[10];

 

  strcpy( s1, "first" );

  strncpy( s2, s1, 5 ); 

  printf("s1 %s s2 %s ",s1,s2);

}

 

Output:

 

  s1 first s2 first