C- strcpy() function
- · strcpy( ) function copies contents of one string into another string. Syntax for strcpy function is given below.
Syntax : strcpy(targetstring , sourcestring);
Example:
·
strcpy ( str1, str2) – It copies
contents of str2 into str1.
·
strcpy ( str2, str1) – It copies
contents of str1 into str2.
Note: While declaring
target string, its size should be equal or greater than the size of the source
string.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ()
{
char s1[20],s2[20];
puts(“Enter a String”);
gets(s1);
strcpy(s2, s1);
#include <conio.h>
#include <string.h>
void main ()
{
char s1[20],s2[20];
puts(“Enter a String”);
gets(s1);
strcpy(s2, s1);
printf("\nSTRING 1:");
puts(str1);
printf("\nSTRING 2:");
puts(str2);
}
No comments:
Post a Comment