-
Notifications
You must be signed in to change notification settings - Fork 0
/
morse.cpp
87 lines (74 loc) · 1.7 KB
/
morse.cpp
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
/*
Author: Vu Huy Nhat Minh - 20191973
This is the main function to execute the program.
Github link for project: https://github.com/VuHuyNhatMinh/KTLT
For more informations, please contact: nminhstickpk@gmail.com
*/
#include <iostream>
#include <fstream>
#include <string>
#include "Dictionary.h"
#include "ErrorChecking.h"
#include "Morse2String.h"
#include "String2Morse.h"
// #define DEBUG
using namespace std;
int main(int argc, char* argv[])
{
/*
Check whether open file data or not
*/
if (!check_open(argv[1]))
{
return 1;
}
/*
Check whether file result exsit or not
If does, overwrite or not
*/
if (!check_exist_out(argv[2]))
{
return 1;
}
/*
Open file data to perform decrypt
*/
ifstream fdata;
fdata.open(argv[1]);
// An object string data to store all text in data file
string data;
getline(fdata, data, '\0');
fdata.close();
/*
Check the file type
*/
// An object string res to store decryption data
string res;;
if (check_type(data))
{
// Check error in morse file
check_morse(data);
#ifdef DEBUG
cout << "This is morse file" << endl;
#endif
// Decrypt to text file
res = Decrypt(data);
}
else
{
// Check error in text file
check_text(data);
#ifdef DEBUG
cout << "This is txt file" << endl;
#endif
// Decrypt to morse file
res = Textmorse(data);
}
/*
Open file result to write result
*/
ofstream fresult;
fresult.open(argv[2]);
fresult << res;
fresult.close();
}