Table of Contents
show
Use of strncpy( ) function
#include<stdio.h>
#include<string.h>
int main()
{
char src[50];
char dest[50];
int n;
puts("Enter string");
gets(src);
puts("Enter the number of characters to copy");
scanf("%d",&n);
puts("Source string is:");
puts(src);
strncpy(dest,src,n);
dest[n] = '\0';
puts("Destination string :");
puts(dest);
return 0;
}
Output
Enter string
Welcome all
Enter the number of characters to copy
3
Source string is:
Welcome all
Destination string :
Wel
Views: 0