-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileInputUtils.c
57 lines (47 loc) · 1002 Bytes
/
FileInputUtils.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
55
56
57
#include "Utils.h"
// check if vbs extension exists
// if exists return true, otherwise false
bool check_vbs_extension(char fname[])
{
if (strstr(fname, ".vbs") != NULL)
{
return true;
}
return false;
}
// check if file exists
// if exists return true, otherwise false
bool file_exists(char fname[])
{
FILE *fp;
if (fopen(fname, "r") != NULL)
{
return true;
}
return false;
}
// count chars of file
unsigned int get_file_size(char fname[])
{
FILE *fp;
fp = fopen(fname,"r");
unsigned int len;
fseek(fp, 0, SEEK_END);
len = ftell(fp);
fclose(fp);
return len;
}
// open, read file, save content into string variable
void get_file_content(char fname[],char content[])
{
FILE *fp;
fp = fopen(fname, "r");
int i = 0;
while(!feof(fp))
{
content[i] = (char) fgetc(fp);
i++;
}
content[i] ='\0';
fclose(fp);
}