Tuesday, April 30, 2013

c Program to Copy String using strcpy()

// Program to Copy String using strcpy()
#include <stdio.h>
#include <string.h>
main()
{
char s1[20], s2[20];
printf("\nEnter string into s1: ");
gets(s1);
strcpy(s2, s1);
printf("\ns2: %s", s2);
getch();
}


(String Copy)

In the C Programming Language, the strcpy function copies the string pointed to by s2 into the object pointed to by s1. It returns a pointer to the destination.

Syntax

The syntax for the strcpy function is:
char *strcpy(char *s1, const char *s2);
s1 is an array where s2 will be copied to.
s2 is the string to be copied.

Returns

The strcpy function returns s1.

No comments:

Post a Comment