Informações

Autores Nicolas Rybowski
Prazo de entrega Sem prazo
Limite de submissão No limitation
Category tags s3, category_malloc, level2

Etiquetas

Entrar

[S3] Improved strcpy

The classic function char *strcpy(char *destination, const char *source); strcpy(3) needs a destination buffer where the source string is copied. We ask you to code a function which allocates a buffer itself, and then performs the copy.

The use of copy functions as memcpy or strcpy is not allowed.

Hint : use malloc(3). Don't forget that malloc can fail sometimes...


buf_strcpy

Write the body of the function buf_strcpy.

/*
* Creates a buffer that has the same size as src, and copies the content of src to this buffer.
*
* @src: string to be copied
* @return: return pointer. if src == NULL or in case of error, return NULL
*
* Remember that strings are terminated with '\0' and that strlen("abc") returns 3 even if 4 bytes are required to store this string.
*/
char *buf_strcpy(const char *src) {