0x0B. C - Malloc, Free
0x0B. C - Malloc, Free
0x0B. C - Malloc, Free
C - malloc, free
README.md
####TASKS
#### [2. He who is not courageous enough to take risks will accomplish
nothing in life](2-str_concat.c)
####[5. It isn't the mountains ahead to climb that wear you out; it's the
pebble in your shoe](100-argstostr.c)
main.h
#ifndef MAIN_H
#define MAIN_H
#endif
_putchar.c
#include "main.h"
#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));
}
0-create_array.c
#include "main.h"
#include <stdlib.h>
/**
* create_array - create array of size size and assign char c
* @size: size of array
* @c: char to assign
* Description: create array of size size and assign char c
* Return: pointer to array, NULL if fail
*
*/
char *create_array(unsigned int size, char c)
{
char *str;
unsigned int i;
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
/**
* _strdup - duplicate to new memory space location
* @str: char
* Return: 0
*/
char *_strdup(char *str)
{
char *aaa;
int i, r = 0;
if (str == NULL)
return (NULL);
i = 0;
while (str[i] != '\0')
i++;
return (aaa);
}
2-str_concat.c
#include "main.h"
#include <stdlib.h>
/**
* str_concat - get ends of input and add together for size
* @s1: input one to concat
* @s2: input two to concat
* Return: concat of s1 and s2
*/
char *str_concat(char *s1, char *s2)
{
char *conct;
int i, ci;
if (s1 == NULL)
s1 = "";
if (s2 == NULL)
s2 = "";
i = ci = 0;
while (s1[i] != '\0')
i++;
while (s2[ci] != '\0')
ci++;
conct = malloc(sizeof(char) * (i + ci + 1));
if (conct == NULL)
return (NULL);
i = ci = 0;
while (s1[i] != '\0')
{
conct[i] = s1[i];
i++;
}
#include "main.h"
#include <stdlib.h>
/**
* alloc_grid - nested loop to make grid
* @width: width input
* @height: height input
* Return: pointer to 2 dim. array
*/
int **alloc_grid(int width, int height)
{
int **mee;
int x, y;
if (width <= 0 || height <= 0)
return (NULL);
if (mee == NULL)
return (NULL);
if (mee[x] == NULL)
{
for (; x >= 0; x--)
free(mee[x]);
free(mee);
return (NULL);
}
}
return (mee);
}
4-free_grid.c
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
/**
* free_grid - frees 2d array
* @grid: 2d grid
* @height: height dimension of grid
* Description: frees memory of grid
* Return: nothing
*
*/
void free_grid(int **grid, int height)
{
int i;
100-argstostr.c
#include "main.h"
#include <stdlib.h>
/**
* argstostr - main entry
* @ac: int input
* @av: double pointer array
* Return: 0
*/
char *argstostr(int ac, char **av)
{
int i, n, r = 0, l = 0;
char *str;
if (ac == 0 || av == NULL)
return (NULL);
#include <stdlib.h>
#include "main.h"
/**
* count_word - helper function to count the number of words in a string
* @s: string to evaluate
*
* Return: number of words
*/
int count_word(char *s)
{
int flag, c, w;
flag = 0;
w = 0;
return (w);
}
/**
* **strtow - splits a string into words
* @str: string to split
*
* Return: pointer to an array of strings (Success)
* or NULL (Error)
*/
char **strtow(char *str)
{
char **matrix, *tmp;
int i, k = 0, len = 0, words, c = 0, start, end;
matrix[k] = NULL;
return (matrix);
}