Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <locale.h>
- #include <string.h>
- #include <stdlib.h>
- #define NAME "array.bin"
- void creatingfile(const char* file) {
- FILE* f = fopen(file, "wb");
- if (!f) {
- printf("Не получилось открыть файл\n");
- return;
- }
- rewind(f);
- int n;
- printf("Введите количество элементов(компонент)\n");
- scanf("%d", &n);
- printf("Введите %d элементов:\n", n);
- for (int i = 0; i < n; i++) {
- double cur_num;
- scanf("%lf", &cur_num);
- fwrite(&cur_num, sizeof(double), 1, f);
- }
- fclose(f);
- }
- void printingfile(const char* file) {
- FILE* f = fopen(file, "rb");
- if (!f) {
- printf("Не получилось открыть файл\n");
- return;
- }
- printf("Содержимое файла:\n");
- rewind(f);
- while (!feof(f)) {
- double el;
- fread(&el, sizeof(double), 1, f);
- if (!feof(f)) {
- printf("%lf\t", el);
- }
- }
- printf("\n");
- fclose(f);
- }
- int main()
- {
- setlocale(LC_ALL, "RUS");
- creatingfile(NAME);
- printingfile(NAME);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement