-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnew.c
39 lines (35 loc) · 1.47 KB
/
ft_strnew.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbutt <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/08 22:31:44 by mbutt #+# #+# */
/* Updated: 2019/03/10 15:05:34 by mbutt ### ########.fr */
/* */
/* ************************************************************************** */
/*
** Description - Allocates (with malloc(3)) and returns a “fresh” string ending
** with ’\0’. Each character of the string is initialized at ’\0’. If the
** allocation fails the function returns NULL.)
** Param #1 - The size of the string to be allocated.
** RETURN VALUES - The string allocataed and initialized to 0.
** Libc Functions - mallo(3).
*/
#include "libft.h"
char *ft_strnew(size_t size)
{
size_t i;
char *memory;
i = 0;
memory = (char *)malloc(sizeof(char) * (size + 1));
if (!(memory))
return (NULL);
else
{
while (i <= size)
memory[i++] = 0;
}
return (memory);
}