strcopy 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

/* strcpy example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str1[]="Sample string";
  char str2[40];
  char str3[40];
  strcpy (str2,str1);//str1 copies to str2
  strcpy (str3,"copy successful");
  printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
  return 0;
}

Example 3: 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 4: strncpy c

char *strncpy(char *dest, const char *src, size_t n)

Tags:

Cpp Example