-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.c
More file actions
102 lines (92 loc) · 1.98 KB
/
util.c
File metadata and controls
102 lines (92 loc) · 1.98 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* util.c - Utility functions.
*
* Author: Debajyoti Nandi
* Created: 2016-07-08
* Modified: 2016-07-13
* License: MIT License (see LICENSE.txt)
*
* Compilation Suggestions:
* CC = gcc #( or clang)
* CFLAGS = -std=gnu11 -O3 #(or, -O2)
* $(CC) $(CFLAGS) -c util.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "util.h"
void print_array(size_t len, const int a[len])
{
printf("[");
for (size_t i = 0; i < len; i++) {
if (i != 0)
printf(", ");
printf("%d", a[i]);
}
printf("]");
}
void print_array_int64(size_t len, const int64_t a[len])
{
printf("[");
for (size_t i = 0; i < len; i++) {
if (i != 0)
printf(", ");
printf("%" PRId64, a[i]);
}
printf("]");
}
void print_array_uint64(size_t len, const uint64_t a[len])
{
printf("[");
for (size_t i = 0; i < len; i++) {
if (i != 0)
printf(", ");
printf("%" PRIu64, a[i]);
}
printf("]");
}
void println_array(size_t len, const int a[len])
{
printf("[");
for (size_t i = 0; i < len; i++) {
if (i != 0)
printf(", ");
printf("%d", a[i]);
}
printf("]\n");
}
void println_array_int64(size_t len, const int64_t a[len])
{
printf("[");
for (size_t i = 0; i < len; i++) {
if (i != 0)
printf(", ");
printf("%" PRId64, a[i]);
}
printf("]\n");
}
void println_array_uint64(size_t len, const uint64_t a[len])
{
printf("[");
for (size_t i = 0; i < len; i++) {
if (i != 0)
printf(", ");
printf("%" PRIu64, a[i]);
}
printf("]\n");
}
void init_array(size_t len, int a[len], int x)
{
for (size_t i = 0; i < len; i++)
a[i] = x;
}
void init_array_int64(size_t len, int64_t a[len], int64_t x)
{
for (size_t i = 0; i < len; i++)
a[i] = x;
}
void init_array_uint64(size_t len, uint64_t a[len], uint64_t x)
{
for (size_t i = 0; i < len; i++)
a[i] = x;
}