This repository has been archived by the owner on Jan 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileHelper.c
85 lines (62 loc) · 1.47 KB
/
fileHelper.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
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
/*
Function definitions of fileHelper.h
*/
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "fileHelper.h"
#include "stringHelper.h"
bool writeTitleTerms(char *title, char *id, FILE* terms){
char *term;
term = strtok(title, " \n,!@#$%^&*+-=<’;\'\":>?/.");
while(term != NULL){
prepStr(term);
prepStr(term);
if(strlen(term) > 2 && strncmp(term, "&#", 2) != 0){
fprintf(terms, "t-%s:%s\n",term, id);
}
term = strtok(NULL, " \n,!@#$%^&*’+-=\'\"<;:>?/.");
}
return true;
}
bool writeBodyTerms(char *body, char *id, FILE* terms){
char *term;
term = strtok(body, " \n,!@#$%^&*+-=<'’;:>\'\"?/.");
while(term != NULL){
prepStr(term);
if(strlen(term) > 2 && strncmp(term, "&#", 2) != 0){
fprintf(terms, "b-%s:%s\n",term, id);
}
term = strtok(NULL, " \n,!@#$%^&*+'’-=<;:>\'\"?/.");
}
return true;
}
bool writePdates(char *date, char *id, FILE* pdates){
fprintf(pdates, "%s:%s\n",date, id);
return true;
}
bool writePrices(char *price, char *id, FILE* prices){
int auxp = atoi(price);
fprintf(prices, "%8d:%s\n", auxp, id);
return true;
}
bool writeAd(char *adRec, char *id, FILE* ads){
fprintf(ads, "%s:%s\n", id, adRec);
return true;
}
bool closeFiles(FILE* terms, FILE* pdates, FILE* prices, FILE* ads){
if(fclose(terms) == EOF){
return false;
}
if(fclose(pdates) == EOF){
return false;
}
if(fclose(prices) == EOF){
return false;
}
if(fclose(ads) == EOF){
return false;
}
return true;
}