strcpy function C code example

Example 1: strcpy in C

#include <stdio.h>
#include <string.h>

int main() {
   char str1[20] = "C programming";
   char str2[20];

   // copying str1 to str2
   strcpy(str2, str1);

   puts(str2); // C programming

   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 implementation in c

while ((*destination++ = *source++) != '\0');

Tags:

C Example