-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.c
101 lines (75 loc) · 3.63 KB
/
format.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*-----------------------------------------------------------------------------+
File Name: format.c
+------------------------------------------------------------------------------+
+------------------------------------------------------------------------------+
Programming III COP4338
Author: Daniel Gonzalez P#4926400
assignment 5: Date Validate / Format
Date: 11/08/2016 ELLECTION DAY!!!!
program description
Input: Accept input for the first program via the command-line arguments.
Input will be the number of valid entries to be redirected from
the dates input file (dates.dat). A zero indicates to input all
entries from the dates input file. Your program should validate
(day, month & year - see page 111 for validation ideas) and skip
corrupt dates in the dates.dat file (see page 159 for scanning
ideas). This validated input will then be piped out to the
second program.
The second program will accept these validated dates in the
month/day/year format and convert each of them to the day,
abbreviated month & year format — both exhibited above. The
abbreviated month should consist of the first three letters of
the month, capitalized. These converted results will be redirected
to the output file (output.dat), followed by a copy of the
original (dates.dat) data.
Output: Generates an output file (output.dat) that contains a
converted list of dates in day, abbreviated month & year
format (i.e. 1 JAN 1900), followed by the original list of
dates in month/day/year format (i.e. 1/1/1900). This output file
will be the result of appending the input file (dates.dat), which
is accessed by the first program, with the result output file
(output.dat), generated by the second program.
+-------------------------------------------------------------------------+
| I Daniel Gonzalez #4926400 hereby certify that this collective work is |
| my own and none of it is the work of any other person or entity. |
+-------------------------------------------------------------------------+
how to compile and execute:
1.Open the terminal
Go to the program folder that contains all the files required for
the program to compile including all header files(*.h).
Run the following command "make"
2.Open the terminal
Go to the program folder that contains all the files required for
the program to compile including all header files(*.h).
COMPILE: "gcc -Wall -w -lm readDate.c dateValidate.c -o validateDate"
Program execution:
From the terminal enter:
“./validateDate < dates.dat [X] | ./format > output.dat"
X: is the amount of validated dates
+-----------------------------------------------------------------------------*/
#include "general.h"
/**----------------------------------------------------------------------------+
//Get a line of data.
//Print data with correct format.
//Print original data. */
int main(int argc, char *argv[])
{
/* Declare variables */
DateKey date;
Data data;
/* Main process */
while (fgets(data.input, MAX_LINE, stdin) != NULL){
if(data.input[0] == HAND_SHAKING_SIGNAL){
break;
}else{
date = getDateKeys(data.input);
printfDate(data.output, DATE_FORMAT_SHORT_MONTH, &date);
fputs(data.output, stdout);
}
}
while (fgets(data.input, MAX_LINE, stdin) != NULL) {
fputs(data.input, stdout);
}
/* Output results */
return NO_ERRORS;
}