Skip to content

Commit c8b349d

Browse files
committed
Adding the file 0-create_array.c and holberton.h
1 parent 5df8ab3 commit c8b349d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

0x0B-malloc_free/0-create_array.c

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "holberton.h"
2+
#include <stdlib.h>
3+
4+
/**
5+
* create_array - creates an array and initializes with specific character
6+
* @size: is the size of the array to be created
7+
* @c: character with the one to be initialized
8+
*
9+
* Return: a pointer to the to the created array, NULL if it fails
10+
*/
11+
12+
char *create_array(unsigned int size, char c)
13+
{
14+
char *ptr;
15+
int i = 0;
16+
17+
if (size == 0)
18+
return (NULL);
19+
20+
ptr = malloc(sizeof(char) * size);
21+
22+
if (ptr == NULL)
23+
return (NULL);
24+
25+
while (size--)
26+
{
27+
ptr[i++] = c;
28+
}
29+
30+
return (ptr);
31+
}

0x0B-malloc_free/holberton.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef HOLBERTON_H
2+
#define HOLBERTON_H
3+
4+
int _putchar(char);
5+
char *create_array(unsigned int, char);
6+
7+
#endif

0 commit comments

Comments
 (0)