Загрузка данных



#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <time.h>

#ifdef _WIN32
#include <io.h>
#define open _open
#define write _write
#define close _close
#else
#include <unistd.h>
#define O_BINARY 0
#endif

int main(int argc, char *argv[])
{
    if (argc != 3)
        return 1;

    int n = atoi(argv[2]);
    int fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
    if (fd == -1)
        return 1;

    srand(time(NULL));

    for (int i = 0; i < n; i++) {
        int16_t x = 0;

        if (rand() % 6 != 0) {
            x = rand() % 32767 + 1;
            if (rand() % 2 == 0)
                x = -x;
        }

        write(fd, &x, sizeof(x));
    }

    close(fd);
    return 0;
}