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
| #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include <Windows.h> // для работы SetConsoleCP, SetConsoleOutputCP
using namespace std;
int main()
{
SetConsoleCP(1251);// установка кодовой страницы win-cp 1251 в поток ввода
SetConsoleOutputCP(1251); // установка кодовой страницы win-cp 1251 в поток вывода
setlocale(LC_ALL, "Rus"); // Подключение русского языка
FILE* h;
int nzps = 0;
//строковая
struct STR {
char str1[20];
//char str2[20];
}vvod;
//символьные
char dstv, dstv2;
//---------------------------Меню--------------------------------------------
do {
cout << "------------------------------------------------------------" << endl;
cout << " Menu" << endl;
cout << "1. Prosmotr texta" << endl;
cout << "2. Dovit' text" << endl;
cout << "3. Redaktirovat' text" << endl;
cout << "4. Udalenie texta" << endl;
cout << "5. Ochistitet' file" << endl;
cout << "6. Spravka" << endl;
cout << "7. Exit" << endl;
cin >> dstv;
switch (dstv) {
//просмотр текста()
case'1': {cout << "Prosmotr texta" << endl;
if ((h = fopen("C:\\fscanf.txt", "rt")) == 0) {
cout << "File pust" << endl; break;
}
fseek(h, 0, SEEK_END);
nzps = ftell(h) / sizeof(STR);
STR* strok = new STR[nzps];
fseek(h, 0, SEEK_SET);
fread(strok, sizeof(STR), nzps, h);
cout << "Kol-vo zapisei- " << nzps << endl;
for (int k = 0; k < nzps; k++) {
cout << strok[k].str1 << endl;;
}
fclose(h);
cout << "" << endl;
break; }
//добавление текста(готово)
case'2': {cout << "Dobavit'text" << endl;
cout << "vedite text" << endl;
cin >> vvod.str1;
h = fopen("C:\\fscanf.txt", "at");
fseek(h, 0, SEEK_END);
fwrite(&vvod, sizeof(STR), 1, h);
fclose(h);
cout << "" << endl;
break; }
//редактировать текст()
case'3': {
int N = 0;
char rd[20];
cout << "Redaktirovat' text" << endl;
cout << "Vvedite izmeniemii text" << endl;
cin >> rd;
h = fopen("C:\\fscanf.txt", "rt");
fseek(h, 0, SEEK_END);
nzps = ftell(h) / sizeof(STR);
STR* strok = new STR[nzps];
fseek(h, 0, SEEK_SET);
fread(strok, sizeof(STR), nzps, h);
fclose(h);
for (int u = 0; u < nzps; u++) {
if (strcmp(rd, strok[u].str1) == 0) {
cout << strok[u].str1 << endl;
N += 1;
}
}
if (N == 0) {
cout << "No date" << endl;
}
cout << "Vvedite novuy stroku" << endl;
cin >> vvod.str1;
h = fopen("C:\\fscanf.txt", "wt");
for (int u = 0; u < nzps; u++) {
if (strcmp(rd, strok[u].str1) != 0)
fwrite(&strok[u], sizeof(STR), 1, h);
}
fclose(h);
h = fopen("C:\\fscanf.txt", "at");
fseek(h, 0, SEEK_END);
fwrite(&vvod, sizeof(STR), 1, h);
fclose(h);
cout << "Zapis' dobavlena" << endl;
cout << "" << endl;
break; }
//удаление текста()
case'4': {
char rd[20];
cout << "Udalenie texta" << endl;
cout << "Vvedite udalyaemii text" << endl;
cin >> vvod.str1;
h = fopen("C:\\fscanf.txt", "rt");
fseek(h, 0, SEEK_END);
nzps = ftell(h) / sizeof(STR);
STR* strok = new STR[nzps];
fseek(h, 0, SEEK_SET);
fread(strok, sizeof(STR), nzps, h);
fclose(h);
h = fopen("C:\\fscanf.txt", "wt");
for (int u = 0; u < nzps; u++)
if (strcmp(vvod.str1, strok[u].str1) != 0)
fwrite(&strok[u], sizeof(STR), 1, h);
fclose(h);
cout << "Zapis'udalena" << endl;
cout << "" << endl;
break; }
//очистка файла(готово)
case'5': {cout << "Ochistitet' file" << endl;
cout << "Vi uvereni chto hotite ochistet' file";
cout << "(Nagmite chislo)" << endl;
cout << "1. Yes" << endl;
cout << "2. No" << endl;
cin >> dstv2;
switch (dstv2) {
case'1': {h = fopen("C:\\fscanf.txt", "wt");
fclose(h);
cout << "File ochishen" << endl;
cout << "" << endl;
}break;
case'2': {cout << "File ne udalen" << endl;
cout << "" << endl;
break; }
}
break; }
case'6': {cout << "Vvod strok po" << endl;
cout << "" << endl;
}break;
}
} while (dstv != '7');
cout << "Dlya vihoda nagmite lybuy klavishu" << endl;
cin.get();
cin.get();
return 0;
} |