C strncpy function

« Previous

Synopsis:

Example

#include <stdio.h>
char *strncpy (char *dest, char *src, int n); 

Description:

The strcpy function copies n characters from src to dest up to and including the terminating null character if length of src is less than n.

Return Value

The strncpy function returns dest.

Example

Example

#include <stdio.h>
int main() {
  char input_str[20];
  char *output_str;
  strncpy(input_str, "Learn", 20);
  printf("input_str: %s\n", input_str);
  /* Reset string */
  memset(input_str, '\0', sizeof( input_str ));
  strncpy(input_str, "Learn", 2);
  printf("input_str: %s\n", input_str);
  /* Reset string */
  memset(input_str, '\0', sizeof( input_str ));
  output_str = strncpy(input_str, "World", 3);
  printf("input_str: %s\n", input_str);
  printf("output_str: %s\n", output_str);
  return 0;
}

Output Will Be :

Output

input_str: NewFile.
input_str: He
input_str: Wor
output_str: Wor


« Previous
Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!