init commit

This commit is contained in:
2025-04-13 21:48:15 +03:00
commit 23255e9121
192 changed files with 12200 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
#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;
}