tgrekov-pipex
HIVE pipex May 2024
Loading...
Searching...
No Matches
arr_cut.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* arr_cut.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/04/22 06:40:30 by tgrekov #+# #+# */
9/* Updated: 2024/05/06 14:18:39 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include <stdlib.h>
21#include "utils.h"
22
32void **arr_cut(void **arr, int len)
33{
34 void **arr2;
35
36 arr2 = malloc(sizeof(void *) * len);
37 if (!arr2)
38 return (err("malloc()", 0));
39 arr2[len] = 0;
40 while (len--)
41 arr2[len] = arr[len];
42 return (arr2);
43}
void ** arr_cut(void **arr, int len)
Create new null-terminated array containing first len elements of arr.
Definition arr_cut.c:32
void * err(const char *str, void *retval)
Wrapper around perror() that always returns retval.
Definition err.c:29