strncpy(): Copying part of strings in C

We can use string function strncpy() to copy part strings.
Part of the second string is added to the first string.
strcpy(destination_string, source_string, n);
We will use this and here is one example.
#include <stdio.h>
#include <string.h>
int main(void){
char var1[20]="First one";
char var2[]="Second two";
return 0;
The output of above code is here, ( first 5 chars of var1 variable is copied to var2 variable )
Firstd two
  • Source string is not affected
  • Destination string is replaced by source string.

Post your comments , suggestion , error , requirements etc here

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 All rights reserved worldwide Privacy Policy Disclaimer