This repository has been archived on 2026-07-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cmc/3sem/seminars/l3/03.с
T
2025-04-13 21:48:15 +03:00

27 lines
515 B
Plaintext
Executable File

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char* argv[]) {
int fdout = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (fdout == -1) {
return 1;
}
unsigned short x;
while (scanf("%hu", &x) == 1) {
unsigned char buf[2];
buf[0] = x >> 8;
buf[1] = x & 0xff;
write(fdout, &x, 2);
}
close(fdout);
return 0;
}