Example program using strcat and strncat 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);
 
    strcat(s1,s2);
    printf("nString built by strcat is %s.",s1);
    printf("nLength of the string built by strcat is %d.",strlen(s1));
 
    strncat(s1,s2,5);
    printf("nString built by strncat using 5 characters is %s.n",s1);
    return 0;
 }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.