This blog is under construction

Sunday, 29 April 2012

strncat example in C

Header file:
    string.h

Synopsis:
    char *strncat(char *dest, char *src, int n);

Description:
     It concatenates the first n characters of string src to string dest.  And it terminates the string dest with '\0';  Returns string dest on success.


strncat function C example:


  #include<stdio.h>
  #include<string.h>
  #include<stdlib.h>

  int main() {
        char data1[100] = "Sample program for", data2[100] = "strncat ";
        strncat(data2, data1, 15);
        printf("Ouput: %s\n", data2);
        return 0;
  }



Output:
jp@jp-VirtualBox:~/cpgms/chap5$ ./a.out
Ouput: strncat Sample program



No comments:

Post a Comment