C Programming
Computer Programming

C program to copies specified number of characters using strncpy() function



Write a program in C to copies only the specified number of characters from source string to destination string using strncpy() function

\* C program to copies specified number of characters using strncpy() function *\

# include < stdio.h >
# include < string.h >
int   main( )
{

char a[50], b[50] ;
int n ;
printf ("\n Enter a source string : ") ;
scanf("%s", a ) ;
printf("\n Enter the digit add in sting : ") ;
scanf("%d", &n ) ;
strncpy ( b, a, n ) ;
b[n] = '\0' ;
printf ("\n Copied string is = %s", b ) ;
printf ("\n Source string is = %s", a ) ;
return 0 ;

}

Output of Program :

Output of C program to copies specified number of characters using strncpy() function