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/02.c
T
2025-04-13 21:48:15 +03:00

53 lines
1.0 KiB
C
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 fdin = open("in", O_RDWR);
if (fdin == -1) {
return 1;
}
double num1, num2;
// Read the first double
if (read(fdin, &num1, sizeof(double)) != sizeof(double)) {
close(fdin);
return 1;
}
// Read the second double
if (read(fdin, &num2, sizeof(double)) != sizeof(double)) {
close(fdin);
return 1;
}
// Move the file pointer back to the beginning
if (lseek(fdin, 0, SEEK_SET) == -1) {
close(fdin);
return 1;
}
// Write the second double first
if (write(fdin, &num2, sizeof(double)) != sizeof(double)) {
close(fdin);
return 1;
}
// Write the first double second
if (write(fdin, &num1, sizeof(double)) != sizeof(double)) {
close(fdin);
return 1;
}
close(fdin);
return 0;
}