-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.c
54 lines (47 loc) · 1.33 KB
/
utils.c
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
/* utils.c
*
* Copyright (C) 2018 < Daniel Finneran, dan@thebsdbox.co.uk >
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the GPL license. See the LICENSE file for details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int stringMatch(char *string1, char *string2)
{
if ((string1) && (string2)) {
while (*string1 == *string2) {
// if both points in strings are null break out of loop
if (*string1 == '\0' || *string2 == '\0') {
break;
}
// move onto next character comparison
string1++;
string2++;
}
// Have we reached the end of the string whilst both have been the same value
if (*string1 == '\0' && *string2 == '\0')
return 1; // Return true (compiler)
else
return 0; // Return false
}
return 0;
}
char *readFile(char *fileName) {
FILE *file = fopen(fileName, "r");
char *code;
size_t n = 0;
int c;
if (file == NULL) return NULL; //could not open file
fseek(file, 0, SEEK_END);
long f_size = ftell(file);
fseek(file, 0, SEEK_SET);
code = malloc(f_size);
while ((c = fgetc(file)) != EOF) {
code[n++] = (char)c;
}
code[n] = '\0';
return code;
}