What is strncpy function in C language ?

stncpy( ) function in C which is basically used to copy one string to another by using n parameters(variables).

What is strncpy function in C language ?
strncpy() in C

Through this article we are going to discuss strncpy( ) function in detail in which we will cover following topics.

Topics:-

  1. strncpy( ) function in c
  2. strncpy( ) function in c example
  3. strncpy( ) function in c syntax
  4. header file for strncpy( ) function in c

strncpy( ) function in C

strncpy( ) function is also known as a built in function or standard library function of C but it is widely know as string function, which are basically used to copy only the left most 'n' character of source string to the  target string variable.
it is also act like string assignment operator in C language.

Header file for strncpy( ) in C

strncpy( ) function is a built in function of C language which are define in <string.h> header file.

Syntax of strncpy( ) in C

strncpy(string1,string2,size_num);

Example of strncpy( ) in C

#include<stdio.h>
#include<string.h>
int main()
{
  char str[15];
  char str1[15]="AceinStudy";
  strncpy(str,str1,10);
  printf("Now string %s in str",str);
  return 0;
}

____________________________________

example of strncpy function in c
Strncpy( ) example
____________________________________

Conclusion

strncpy( ) function in C is basically used to copy the string from one string to other by using n parameters.

Post a Comment (0)
Previous Post Next Post