The strcat Function

 Syntax: 

      char *strcat(char *str1, const chat *str2);

 The strcat functin appends the string pointed to by str2 to the end of the string pointed to by str1. The termination null character of str1 is overwritten.The procrss stops when the termianating null character of str2 is copied.The argument str1 is returned. str1 should be big enough to storethe contents of str2.

#include<stdio.h>

#include<string.h>

int main()

{

   char str1[50] = "Programming";

   char str2[] = " In C";

   strcat(str1, str2);

   printf("\n str1:  %s", str1);

}


Output

str1:  Programming In C


The strncat function

syntax:

    char *strncat(char *str1, const char *str2, size_t n);

Appends the string pointed to by str2 to the end of the string pointed to by str1 up to n characters long. The terminating null character of str1 is overwritten. Copying stops when n characters are copied or the terminating null character of str2 is copied. A terminating null character is appended to str1 before returning to the calling functon.

#include<stdio.h>

#include<string.h>

int main()

{

     char str1[50] = "Programming";

     char str2[] =  "In C";

     strncat(str1, str2, 2);

     printf("\n str1:  %s",  str1);

}


Output

  Str1:  Programming In


Comments