strcpy and strncpy in C

#include <stdio.h>
 #include <string.h>
 
 int main(){
    char s1[80],s2[10];
    int n;
 
    printf("Enter two strings : ");
    scanf("%s%s",s1,s2);
 
    strcpy(s1,s2);
    printf("nString created by strcpy is %s.",s1);
    printf("nLength of the new string is %d.",strlen(s1));
 
    strncpy(s1,s2,5);
    s1[5]='';
    printf("nString created by strncpy using 5 characters is %s.n",s1);
    return 0;
 }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.