strcpy c example
Example 1: strcpy
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[]="Sample string";
char str2[40];
char str3[40];
strcpy (str2,str1);
strcpy (str3,"copy successful");
printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
return 0;
}
Example 2: strcpy en c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char Temp[255];
strcpy(&Temp,"Gladir");
strcpy(&Temp,"ABC");
strcpy(&Temp,"Gladir.com");
puts(&Temp);
return 0;
}
Example 3: strcpy c implementation
#include <stdio.h>
char* strcpy(char* destination, const char* source)
{
if (destination == NULL)
return NULL;
char *ptr = destination;
while (*source != '\0')
{
*destination = *source;
destination++;
source++;
}
*destination = '\0';
return ptr;
}
int main(void)
{
char source[] = "Techie Delight";
char destination[25];
printf("%s\n", strcpy(destination, source));
return 0;
}