strncpy Function

  • It copies up to count characters from *str2 to *str1 .
  • It returns a pointer to str1 .


  • Syntax:

      char *strncat(char *str1, const char *str2, size_t count);
     Note : 
    1. str2 must be a pointer to a null-terminated string .
    2. If *str2 has less than 'count' characters, nulls will be appended to *str1 until count characters have been copied .
    3. If *str2 is longer than count characters, the result *str1 will not be null terminated .

    Example:

    #include <stdio.h>
    
    #include <string.h>
    
    
    
    int main()
    
    {
    
      char str1[128]="Anuj is awesome !", str2[80];
    
    
    
      strncpy(str2, str1, 79);
    
    
    
      printf("%s",str2);
    
      return 0;
    
    }
    Back