-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters