data_structures
array_indexof.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* array_indexof.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/16 23:24:52 by unite #+# #+# */
10 /* Updated: 2020/09/07 23:41:04 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "array.h"
15 
16 ssize_t array_indexof(const t_array *array, const void *val)
17 {
18  size_t i;
19 
20  if (array->type->cmp == NULL)
21  ds_exit_set(EINVAL);
22  i = 0;
23  while (i < array->size)
24  {
25  if (array->type->cmp(array->arr[i], val) == 0)
26  return (i);
27  i++;
28  }
29  return (-1);
30 }
s_type::cmp
int(* cmp)(const void *, const void *)
(optional) A function ponter used to compare members of this data type
Definition: types.h:52
array.h
s_array::type
const t_type * type
The type of items in this array.
Definition: array.h:52
s_array::arr
void ** arr
The data.
Definition: array.h:51
s_array
A resizable array.
Definition: array.h:47
array_indexof
ssize_t array_indexof(const t_array *array, const void *val)
Returns the index at which the specified value is found in the array, or -1 if the value isn't the ar...
Definition: array_indexof.c:16
ds_exit_set
void ds_exit_set(int err)
Set errno to the specified value, print the error message, and exit the process.
Definition: ds_exit_set.c:22