Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <limits.h>
- void create(char *name) {
- FILE *f;
- int n, a;
- if ((f = fopen(name, "wb")) == NULL) {
- printf("Ошибка при записи чисел в файл");
- return;
- }
- else {
- printf("Введите число чисел, которые хотите записать в файл:\n");
- scanf("%d", &n);
- printf("\nВведите числа:\n");
- for (int i = 0; i < n; i++) {
- scanf("%d", &a);
- fwrite(&a, sizeof(a), 1, f);
- }
- return;
- }
- }
- void output(char *name) {
- FILE *f;
- int a;
- if ((f = fopen(name, "rb")) == NULL)
- printf("Ошибка при чтении файла");
- else {
- printf("\nЧисла в файле:\n");
- while (fread(&a, sizeof(int), 1, f) == 1)
- printf("%d ", a);
- fclose(f);
- }
- }
- int main() {
- int x;
- FILE *out = fopen("output.bin", "wb");
- create("input.bin");
- output("input.bin");
- FILE *in = fopen("input.bin", "rb");
- for (int i = INT_MAX; i >= INT_MIN; i--)
- while (fread(&x, sizeof(int), 1, in) == 1)
- if (x == i)
- fwrite(&x, sizeof(int), 1, out);
- fclose(out);
- output("output.bin");
- return 0;
- }
Add Comment
Please, Sign In to add comment