Strncat Implementation in C

STRNCAT – append part of a string to another.
strncat appends at most N characters from the string “s2” to the end of the string “s1”. If string “s2” contains less than N characters, “strncat” will stop when it encounters the terminating ‘\0’.

Syntax :ptr = strncat( s1, s2, N )

char *s1: Points to a string terminated by the usual ‘\0’.
const char *s2: ┬áPoints to a string whose characters will be appended to the end of “s1”.
size_t N: ┬áMaximum number of characters from string “s2” that should be appended to “s1”.
char *ptr: points to the new string (“s1”).

char *(strncat)(char *s1, const char * s2, size_t n)
char *s = s1;
while (*s != ‘\0’)
while (n != 0 && (*s = *s2++) != ‘\0’) {
if (*s != ‘\0’)
*s = ‘\0’;
return s1;

About mohan

This is Mohan Jayapalan author of TechPages Blog.I am a part time blogger and Currently working for private Software Concern.

© Copyright 2010-2016 · All Rights Reserved · Powered by WordPress ·