Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
regust
/
IAG0582
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8e22c65b
authored
Feb 22, 2017
by
Raul.Leemet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Näited
parent
55248ef2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
167 additions
and
0 deletions
Praktikum4/n2ide.c
Praktikum4/n2ide.c
0 → 100644
View file @
8e22c65b
#include <stdio.h>
#include <string.h>
typedef
struct
{
char
date
[
9
];
}
dates
;
int
CheckFile
(
FILE
*
input
);
int
FileLength
(
FILE
*
input
);
void
GetDataFromFile
(
dates
DateArray
[],
FILE
*
input
);
void
ChangeFormat
(
dates
DateArray
[],
int
lines
);
void
CheckDate
(
dates
DateArray
[],
int
lines
);
int
main
()
{
char
*
InputFileName
=
"kuup2evad.txt"
;
FILE
*
sisse
;
int
file
=
0
;
int
lines
=
0
;
int
i
=
0
;
sisse
=
fopen
(
InputFileName
,
"r"
);
file
=
CheckFile
(
sisse
);
if
(
file
)
{
//Eelmises tunnis n2idatud kuidas tegelt v6iks k2ituda
return
0
;
}
//Get the Number of lines in the document
lines
=
FileLength
(
sisse
);
dates
DateArray
[
lines
];
GetDataFromFile
(
DateArray
,
sisse
);
fclose
(
sisse
);
ChangeFormat
(
DateArray
,
lines
);
CheckDate
(
DateArray
,
lines
);
return
0
;
}
int
CheckFile
(
FILE
*
input
)
{
if
(
input
==
NULL
)
{
printf
(
"Could not open file
\n
"
);
return
1
;
}
printf
(
"File Open was succesful
\n
"
);
return
0
;
}
int
FileLength
(
FILE
*
input
)
{
int
lines
=
0
;
char
ch
;
while
((
ch
=
fgetc
(
input
))
!=
EOF
)
{
if
(
ch
==
'\n'
)
{
lines
++
;
}
}
return
lines
;
}
void
GetDataFromFile
(
dates
DateArray
[],
FILE
*
input
)
{
int
i
=
0
;
//Set the file pointer to the begging of the file
rewind
(
input
);
while
(
fscanf
(
input
,
"%s"
,
DateArray
[
i
].
date
)
!=
EOF
)
{
i
++
;
}
}
void
ChangeFormat
(
dates
DateArray
[],
int
lines
)
{
int
i
;
int
j
;
char
buffer
;
for
(
i
=
0
;
i
<
lines
;
i
++
)
{
for
(
j
=
0
;
j
<
4
;
j
++
)
{
buffer
=
DateArray
[
i
].
date
[
j
];
DateArray
[
i
].
date
[
j
]
=
DateArray
[
i
].
date
[
j
+
4
];
DateArray
[
i
].
date
[
j
+
4
]
=
buffer
;
}
}
}
void
CheckDate
(
dates
DateArray
[],
int
lines
)
{
int
i
;
int
bad
=
0
;
char
*
EUname
=
"EU.txt"
;
char
*
USname
=
"US.txt"
;
char
*
notdate
=
"notdate.txt"
;
FILE
*
EU
;
FILE
*
US
;
FILE
*
nodate
;
EU
=
fopen
(
EUname
,
"w"
);
US
=
fopen
(
USname
,
"w"
);
nodate
=
fopen
(
notdate
,
"w"
);
for
(
i
=
0
;
i
<
lines
;
i
++
)
{
if
(
DateArray
[
i
].
date
[
0
]
>
'0'
&&
DateArray
[
i
].
date
[
0
]
<
'3'
)
{
if
(
DateArray
[
i
].
date
[
0
]
==
'1'
&&
DateArray
[
i
].
date
[
1
]
<
'9'
)
{
fprintf
(
nodate
,
"%s"
,
DateArray
[
i
].
date
);
}
else
{
if
(
DateArray
[
i
].
date
[
4
]
<
'4'
)
{
if
((
DateArray
[
i
].
date
[
4
]
==
'1'
&&
DateArray
[
i
].
date
[
5
]
<
'3'
)
||
(
DateArray
[
i
].
date
[
4
]
==
'0'
&&
DateArray
[
i
].
date
[
5
]
<=
'9'
))
{
if
((
DateArray
[
i
].
date
[
6
]
==
'3'
&&
DateArray
[
i
].
date
[
7
]
<
'2'
)
||
(
DateArray
[
i
].
date
[
6
]
<
'3'
&&
DateArray
[
i
].
date
[
7
]
<=
'9'
))
{
fprintf
(
EU
,
"%s EU Okey
\n
"
,
DateArray
[
i
].
date
);
}
}
else
if
((
DateArray
[
i
].
date
[
4
]
==
'3'
&&
DateArray
[
i
].
date
[
5
]
<
'2'
)
||
(
DateArray
[
i
].
date
[
4
]
<
'3'
&&
DateArray
[
i
].
date
[
5
]
<=
'9'
))
{
if
((
DateArray
[
i
].
date
[
6
]
==
'1'
&&
DateArray
[
i
].
date
[
7
]
<
'3'
)
||
(
DateArray
[
i
].
date
[
6
]
==
'0'
&&
DateArray
[
i
].
date
[
7
]
<=
'9'
))
{
fprintf
(
US
,
"%s US Okey
\n
"
,
DateArray
[
i
].
date
);
}
}
}
}
}
else
{
fprintf
(
nodate
,
"%s"
,
DateArray
[
i
].
date
);
bad
++
;
}
}
fclose
(
EU
);
fclose
(
US
);
fclose
(
nodate
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment