Skip to content

Commit

Permalink
adding 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfosse committed Mar 10, 2017
1 parent 58ed74b commit 278ec8f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 0x0B-more_malloc_free/0-main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "holberton.h"
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

/**
* main - check the code for Holberton School students.
*
* Return: Always 0.
*/
int main(void)
{
char *c;
int *i;
float *f;
double *d;

c = malloc_checked(sizeof(char) * 1024);
printf("%p\n", (void *)c);
i = malloc_checked(sizeof(int) * 402);
printf("%p\n", (void *)i);
f = malloc_checked(sizeof(float) * 100000000);
printf("%p\n", (void *)f);
d = malloc_checked(INT_MAX);
printf("%p\n", (void *)d);
free(c);
free(i);
free(f);
free(d);
return (0);
}
17 changes: 17 additions & 0 deletions 0x0B-more_malloc_free/0-malloc_checked.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "holberton.h"
/**
* malloc_checked - alloctes memory using malloc.
* @b: size.
* Return: returns pointer, otherwise 98 on fail.
*/
void *malloc_checked(unsigned int b)
{
void *temp;

temp = malloc(b);
if (temp == NULL)
{
exit(98);
}
return (temp);
}
3 changes: 3 additions & 0 deletions 0x0B-more_malloc_free/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0x0B-more_malloc_free

add content here...
13 changes: 13 additions & 0 deletions 0x0B-more_malloc_free/_putchar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <unistd.h>

/**
* * _putchar - writes the character c to stdout
* * @c: The character to print
* *
* * Return: On success 1.
* * On error, -1 is returned, and errno is set appropriately.
* */
int _putchar(char c)
{
return (write(1, &c, 1));
}
Binary file added 0x0B-more_malloc_free/a
Binary file not shown.
10 changes: 10 additions & 0 deletions 0x0B-more_malloc_free/holberton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef HOLBERTON
#define HOLBERTON

#include <stdio.h>
#include <stdlib.h>

void *malloc_checked(unsigned int b);
int _putchar(char c);

#endif

0 comments on commit 278ec8f

Please sign in to comment.