-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneral.h
More file actions
160 lines (123 loc) · 6.05 KB
/
general.h
File metadata and controls
160 lines (123 loc) · 6.05 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*-----------------------------------------------------------------------------+
File Name: General.h
+------------------------------------------------------------------------------+
+------------------------------------------------------------------------------+
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).
"gcc -Wall -w -lm dateValidate.c Game.c Deck.c Card.c Player.c -o poker"
Program execution:
From the terminal enter:
“./validateDate < dates.dat [X] | ./format > output.dat"
X: is the amount of validated dates
+-----------------------------------------------------------------------------*/
#include <stdio.h> /* using fgets, fputs, fputc, sscanf */
#include <stdlib.h> /* using atoi, malloc, realloc, free*/
#include <string.h> /* using strcpy, strncat */
#include <ctype.h> /* using isspace */
#include <limits.h> /* using INT_MAX */
#include <math.h> /* using fmod */
/* Defines */
#define MAX_LINE 256 /* maximum line size*/
#define MAX_MONTH_NAME 10 /*maximum amount of chars
for a month name*/
#define MIN_FILE_LINES 70 /* minimum amount of lines in file*/
#define HAND_SHAKING_SIGNAL '\t' /* character to signal end of input*/
#define VALID_KEYS 3 /* number of variables
returned from valid scan*/
#define LB_ORIGINAL_DATA "Original Data:" /*Label for original data*/
#define MAX_AMOUNT_ALLOWED_ARGS 2 /* maximum amount of arguments */
#define LEAP_YEAR 4 /* frequency in which a
leap year happens*/
#define ENABLE_ERROR FALSE /* enable to print errors
to the console */
/* program constants */
static const char * ERROR_DESCRIPTIONS [] = {"No errors",
"Error",
"Unable to read date",
"Date contains decimals",
"Date values are huge",
"Month is Invalid",
"Day is invalid"};
static const char * MONTH_NAMES_SHORT [] = {
"INVALID","JAN", "FEB", "MAR",
"APR", "MAY", "JUN", "JUL",
"AUG", "SEP", "OCT",
"NOV", "DEC"};
/* type definitions and structs */
typedef enum {FALSE, TRUE} Boolean;
typedef enum {DATE_FORMAT_SLASH_DOUBLE,
DATE_FORMAT_SLASH,
DATE_FORMAT_SHORT_MONTH} Format;
typedef enum {NO_ERRORS,
ERRORS,
ERRORS_UNABLE_TO_READ,
ERRORS_DECIMALS_IN_DATE,
ERRORS_HUGE_DATE,
ERRORS_INVALID_MONTH,
ERRORS_INVALID_DAY} Error;
typedef struct Line{
char content[MAX_LINE];
} Line;
typedef struct LineList{
Line * lines;
int size;
int capacity;
} LineList;
typedef struct DateKey{
int day;
int month;
int year;
Error error;
} DateKey;
typedef struct Data{
char input [MAX_LINE];
char output [MAX_LINE];
char error [MAX_LINE];
} Data;
/* function prototypes */
Boolean appendToLineList(LineList * , const char *);
void freeLineList(LineList * );
DateKey getDateKeys(char *);
Boolean hasValidDateType(DateKey *, double, double, double);
void initializeLineList(LineList * );
Boolean isLeapYear(int );
Boolean isValidDate(DateKey *);
void printError(char *, char *, Error);
void printfDate(char * , Format, DateKey * );