summaryrefslogtreecommitdiff
path: root/graphs/piscine/null_terminated_arrays/null_terminated_arrays.c
blob: 32d2a17cf939135b778f9b2606052fecd474146a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "null_terminated_arrays.h"

#include <assert.h>
#include <stddef.h>
#include <stdio.h>

void reverse_array(const char **arr)
{
    const char **p;
    for (p = arr; *p; p++)
    {
        continue;
    }
    p--;

    while (p > arr)
    {
        const char *tmp = *p;
        *p = *arr;
        *arr = tmp;
        arr++;
        p--;
    }
}

void reverse_matrix(const char ***matrix)
{
    const char ***p;
    for (p = matrix; *p; p++)
    {
        continue;
    }
    p--;

    while (p > matrix)
    {
        reverse_array(*p);
        reverse_array(*matrix);
        const char **tmp = *p;
        *p = *matrix;
        *matrix = tmp;
        matrix++;
        p--;
    }

    if (p == matrix)
    {
        reverse_array(*matrix);
    }
}