4.28.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()

1 comment:

  1. string catenation

    char *strcat(char *dest, const char *src)
    {
    char *real_string;
    real_string=dest;

    while(*dest)
    dest++;
    while(*dest++ =*src++)
    ;
    return (real_string);
    }

    how it works....plz help me bro i dont understand....i know pointer.....plz plz plz explain it ( which address where ,whom pointed)....

    ReplyDelete