Δημοσιεύτηκε: 08 Απρ 2012, 15:56
από migf1
Και με sanity checks, η concat() γίνεται έτσι... (ένα-ένα τα βλέπω :lol:) ...

Μορφοποιημένος Κώδικας: Επιλογή όλων
char *concat( const char *s1, const char *s2 )
{
char *result= NULL;

/* sanity checks */
if ( !s1 || !s2 )
return NULL;

/* δυναμική δέσμευση (εναλλακτική, πιο συμπτυγμένη σύνταξη... απλώς εγκυκλοπαιδικά) */
if ( NULL == (result = malloc(strlen(s1) + strlen(s2) + 1) )
return NULL;

strcpy(result, s1);
strcat(result, s2);

return result;
}