Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- bool mseek(int i, FILE* f) {
- int p = ftell(f);
- fseek(f, 0, SEEK_SET);
- int n = 0, c;
- while (!feof(f)) { fread(&c, sizeof(c), 1, f); if (c == i) n++; if (n > 2) break; }
- fseek(f, p, SEEK_SET);
- return n == 2;
- }
- int main(void)
- {
- setlocale(LC_CTYPE, "Russian");
- using namespace std;
- FILE* fa;
- FILE* fb;
- int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 123, 24, 32 ,12 };
- int t[18], i, j = 0;
- fopen_s(&fa, "a.txt", "a+");
- fopen_s(&fb, "b.txt", "w+");
- if (fa == NULL)
- {
- perror("Oшибка открытия файла a.txt");
- return EXIT_FAILURE;
- }
- while (!feof)
- {
- for (int i = 0; i <= 18; i++)
- {
- fread(&t[i], sizeof(int), 1, fa);
- if (mseek(t[i], fa)) fwrite(&array[i], sizeof(int), 1, fb);
- }
- }
- fclose(fa);
- fclose(fb);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement