-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
200 lines (179 loc) · 4.26 KB
/
main.cpp
File metadata and controls
200 lines (179 loc) · 4.26 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "editor.h"
#include "string.h"
#include <cstdlib>
void mainmenu(){
system("clear");
cout << "================================================" <<endl;
cout << " Commands " <<endl;
cout << "a: Modify part of a line i: Modify line " <<endl
<< "b: Remove a line j: Find line " <<endl
<< "c: Display line k: Insert line " <<endl
<< "d: Read file l: Save file " <<endl
<< "e: Find part of a line m: Display all " <<endl
<< "f: Create file n: Delete all " <<endl
<< "g: Cover file content " <<endl
<< "h: Display length x: Exit " <<endl
<<"=================================================" <<endl<<endl;
// cout <<"-------------------------------------------------" <<endl
// <<" Current State of File " <<endl
// <<" " <<endl;
}
int main()
{
Link link;
char input = 'h';
string file_name_1, file_name_2, str_1, str_2;
int num;
system("clear");
cout<< "=====================================================" <<endl
<< " The editor has been activated " <<endl
<< "=====================================================" <<endl;
cout << "Enter file name: ";
cin >> file_name_1;
link.setStart();
link.setEnd();
link.read_from_infile(file_name_1);
// system("clear");
mainmenu();
do{
switch(input)
{
//Modify Part of a Line
case'a':
cout << "Enter line number: ";
cin >> num;
cout << endl;
cout << "Enter string: ";
cin >> str_1;
cout << endl;
link.changeline(num,str_1);
// mainmenu();
link.print();
break;
//Remove a line
case'b':
cout << "Enter line number: ";
cin >> num;
cout << endl;
link.deleteoneline(num);
// link.print();
// mainmenu();
link.print();
break;
//Dislay Line
case'c':
cout << "Enter line number: ";
cin >> num;
cout << endl;
link.setpos(num);
link.displayoneline();
// mainmenu();
link.print();
break;
//Read File
case'd':
link.clear();
link.read_from_infile(file_name_1);
link.print();
// mainmenu();
break;
//Find Part of a line
case'e':
cout << "Enter string: ";
cin >> str_1;
link.findinallstring(str_1);
// mainmenu();
link.print();
break;
//Create file
case'f':
char new_file[30];
cout << "Enter file name: ";
cin >> new_file;
cout << endl;
mainmenu();
link.print();
break;
//Cover File Content
case'g':
cout << "Enter file name: ";
cin >> file_name_2;
cout << endl;
link.save_to_file(file_name_2);
// mainmenu();
link.print();
break;
//Display Length
case'h':
link.longlength();
// mainmenu();
// link.print();
break;
//modify line
case'i':
cout << "Enter line number: ";
cin >> num;
cout << endl;
cout << "Enter string: ";
cin >> str_1;
cout << endl;
link.changeline(num,str_1);
// mainmenu();
link.print();
break;
//find line
case'j':
cout << "Enter string: ";
cin >> str_1;
cout << endl;
link.findappointstring(str_1);
// mainmenu();
link.print();
break;
//insert line
case'k':
cout << "Enter line number (preceeding): ";
cin >> num;
cout << endl;
cout << "Enter string: ";
cin >> str_1;
cout << endl;
link.insert(num,str_1);
link.print();
// mainmenu();
link.print();
break;
//save file
case'l':
link.save_to_file(file_name_1);
// mainmenu();
link.print();
cout << "File saved";
break;
//display all
case'm':
// link.print();
mainmenu();
link.print();
break;
//clear screen
case'n':
mainmenu();
link.print();
break;
/*
case 'h':
system("clear");
mainmenu();
link.print();
break;
*/
default:
cout << "Invalid command" << endl;
// mainmenu();
}
cout <<"Command:";
cin >> input;
}while (input !='x');
return 0;
}