Program Discussion :: Strings
8 / 60
Write a function to implement strncpy using recursion.
Answer:
#include
#include
int main()
{
char s1[100],s2[100];
int n;
printf("Enter the string: ");
scanf("%s",s1);
printf("Enter the no. of characters to be copied: ");
scanf("%d",&n);
printf("String 1: %s ",s1);
printf("String 2 after performing strncpy(): %s",strncpy(s2,s1,n));
return 0;
}
Asked In ::
Language:
Siddhartha Paul
19 Jun, 2019 2:16 PM
#include<stdio.h>
#include<string.h>
int main()
{
char s1[100],s2[100];
int n;
printf("Enter the string: ");
scanf("%s",s1);
printf("Enter the no. of characters to be copied: ");
scanf("%d",&n);
printf("String 1: %s ",s1);
printf("String 2 after performing strncpy(): %s",strncpy(s2,s1,n));
return 0;
}