-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpp
67 lines (59 loc) · 1.46 KB
/
util.cpp
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
#include "driver.h"
char* get_arg(int argc, char** argv, const char* key)
{
char* val = NULL;
int keylen = strlen(key);
for(int i = 1; i < argc; i++)
{
char* token = argv[i];
if(strncmp(token, "-", 1) != 0)
continue;
token += 1;
if(strncmp(token, key, keylen) != 0)
continue;
token += (keylen+1);
val = token;
}
return val;
}
int print_error ( const char* msg)
{
fprintf(stdout, "Error: %s.\n", msg);
return 0;
}
int print_array (int *array, int size, const char *msg, FILE *fp)
{
fprintf(fp, "%s: ", msg);
fprintf(fp, "[");
for (int i=0;i<size-1;i++)
fprintf(fp, "%d, ", array[i]);
fprintf(fp, "%d]\n", array[size-1]);
return 0;
}
int print_array (long int *array, long int size, const char *msg, FILE *fp)
{
fprintf(fp, "%s: ", msg);
fprintf(fp, "[");
for (int i=0;i<size-1;i++)
fprintf(fp, "%d, ", array[i]);
fprintf(fp, "%d]\n", array[size-1]);
return 0;
}
int print_array (double *array, int size, const char *msg, FILE *fp)
{
fprintf(fp, "%s: ", msg);
fprintf(fp, "[");
for (int i=0;i<size-1;i++)
fprintf(fp, "%.1f, ", array[i]);
fprintf(fp, "%.1f]\n", array[size-1]);
return 0;
}
int print_array (char **array, int size, const char *msg, FILE *fp)
{
fprintf(fp, "%s: ", msg);
fprintf(fp, "[");
for (int i=0;i<size-1;i++)
fprintf(fp, "%s, ", array[i]);
fprintf(fp, "%s]\n", array[size-1]);
return 0;
}