Copy a string: Difference between revisions

→‎[[C]]: organized a bit more
(→‎[[Python]]: --- comment on object "interning")
(→‎[[C]]: organized a bit more)
Line 33:
dst$ = src$
 
==[[{{header|C]]}}==
// ===Using strdup===
[[Category:C]]
// Using strdup
const char* src = "Hello";
char* dst = strdup(src);
 
// ===Using malloc/strcpy===
const char* src = "Hello";
int len = strlen(src);
Line 45 ⟶ 44:
strcpy(dst, src);
 
// ===Using malloc/strncpy===
const char* src = "Hello";
int len = strlen(src);
Line 51 ⟶ 50:
strncpy(dst, src, len+1); dst[len] = 0;
 
// ===Using static buffer===
const char* src= "Hello";
static char dst[80];