Skip to content

Commit

Permalink
adding 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfosse committed Mar 10, 2017
1 parent 5738cae commit c88cd2a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 0x0B-more_malloc_free/3-array_range.c
Original file line number Diff line number Diff line change
@@ -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);
}
47 changes: 47 additions & 0 deletions 0x0B-more_malloc_free/3-main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "holberton.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
* 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);
}
Binary file added 0x0B-more_malloc_free/d
Binary file not shown.
2 changes: 2 additions & 0 deletions 0x0B-more_malloc_free/holberton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c88cd2a

Please sign in to comment.