diff --git a/0x0B-more_malloc_free/3-array_range.c b/0x0B-more_malloc_free/3-array_range.c new file mode 100644 index 0000000..c25998d --- /dev/null +++ b/0x0B-more_malloc_free/3-array_range.c @@ -0,0 +1,27 @@ +#include "holberton.h" + +/** + * aray_range - creates an array of ints. + * @min: min size. + * @max: max size. + * Return: returns pointer, NULL on fail. + */ +int *array_range(int min, int max) +{ + int *temp; + int i, size; + + if (min > max) + return (NULL); + + size = max - min + 1; + temp = malloc(size * sizeof(temp)); + + if (temp == NULL) + return (NULL); + + for (i = 0; i < size; i++, min++) + temp[i] = min; + + return (temp); +} diff --git a/0x0B-more_malloc_free/3-main.c b/0x0B-more_malloc_free/3-main.c new file mode 100644 index 0000000..99719ba --- /dev/null +++ b/0x0B-more_malloc_free/3-main.c @@ -0,0 +1,47 @@ +#include "holberton.h" +#include +#include +#include + +/** + * simple_print_buffer - prints buffer in hexa + * @buffer: the address of memory to print + * @size: the size of the memory to print + * + * Return: Nothing. + */ +void simple_print_buffer(int *buffer, unsigned int size) +{ + unsigned int i; + + i = 0; + while (i < size) + { + if (i % 10) + { + printf(" "); + } + if (!(i % 10) && i) + { + printf("\n"); + } + printf("0x%02x", buffer[i]); + i++; + } + printf("\n"); +} + +/** + * main - check the code for Holberton School students. + * + * Return: Always 0. + */ +int main(void) +{ + int *a; + + a = array_range(0, 10); + simple_print_buffer(a, 11); + free(a); + return (0); +} diff --git a/0x0B-more_malloc_free/d b/0x0B-more_malloc_free/d new file mode 100755 index 0000000..60161d2 Binary files /dev/null and b/0x0B-more_malloc_free/d differ diff --git a/0x0B-more_malloc_free/holberton.h b/0x0B-more_malloc_free/holberton.h index e19109e..aaa2056 100644 --- a/0x0B-more_malloc_free/holberton.h +++ b/0x0B-more_malloc_free/holberton.h @@ -8,5 +8,7 @@ void *malloc_checked(unsigned int b); int _putchar(char c); char *string_nconcat(char *s1, char *s2, unsigned int n); void *_calloc(unsigned int nmemb, unsigned int size); +int *array_range(int min, int max); + #endif