C strncpy()

<<Previous

Next >>





This function is used to copy the specified number of characters from source to destination.

Syntax:
	char *strcpy(char *dest, const char *src, size_t number);
For example:
strncpy(dest,source,4)-this copies only 4 characters from source string to dest string.

Note: size_t treats as an integer type.

Following is an example program using strncpy()

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


main()
{
  char source[]={’W’,‘E’,‘L’,‘C’, ‘O’,‘M’,‘E’};
  char dest[10]=" ";
  clrscr();
  printf("The source string is %s",source);
  strncpy(dest,source,4);
  printf("The destination string after copy %s",dest);
  return(0);
}

Output:

The source string is WELCOME
The destination string after copy WELC

<< Previous

Next >>







C strncpy()

<<Previous

Next >>





This function is used to copy the specified number of characters from source to destination.

Syntax:
	char *strcpy(char *dest, const char *src, size_t number);
For example:
strncpy(dest,source,4)-this copies only 4 characters from source string to dest string.

Note: size_t treats as an integer type.

Following is an example program using strncpy()

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


main()
{
  char source[]={’W’,‘E’,‘L’,‘C’, ‘O’,‘M’,‘E’};
  char dest[10]=" ";
  clrscr();
  printf("The source string is %s",source);
  strncpy(dest,source,4);
  printf("The destination string after copy %s",dest);
  return(0);
}

Output:

The source string is WELCOME
The destination string after copy WELC

<< Previous

Next >>







Learn about Hashing and Hash table

Learn Expression Tree

OS Kernel Architecture

OS Arcitecture of Windows, Linux and MacOS

Learn OS scheduling Algorithms