Sunday, 28 April 2013

strcpy()

This function copies the contents of one string into another.
The base address of the source and target strings should be supplied to this function.

Note: If target_string is not empty and it is uses in strcpy() function, then its overlap with source_string.

syntax:

strcpy("target_string","source_string");

example:

strcpy(target_string,source_string);

illustrate uses strcpy() in C program:


/c program for illustrate of strcpy() function*/
#include<stdio.h>
int main()
{
 char source[40],target[40];

 printf("Enter any string : ");
 gets(source);
 strcpy(target,source);
 printf("Target %s=Source %s",target,source);
 getch();
 return 0;
}

The output of above program would be:


Output of strcpy() function uses in C program
Figure: Screen shot of strcpy() uses in C program

Related Article:

  1. List of standard library function
  2. strlen()

No comments:

Post a Comment