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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <stdbool.h>
#include "fill_array.h"

// you are free to copy/adapt from this file

/**
 * fill array with increasing numbers starting at 1
 * length to fill
 * if successful, return true
 * if unsuccessful, return false and put message in a_error
 */
bool fill_array(int* numbers, int numbers_len, char** a_error) {
    if (numbers_len < 0) {
        *a_error = "numbers_len cannot be negative";
        return false;
    }
    if (numbers == NULL) {
        *a_error = "numbers cannot be NULL";
        return false;
    }
    for (int i = 0; i < numbers_len; i++) {
        numbers[i] = i + 1;
    }
    return true;
}

© Copyright 2022 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.