SCR/SCR1.2/TP11/put_nub.c
2023-03-03 21:52:30 +01:00

28 lines
597 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[]){
if (argc != 4){
fprintf(stderr, "%c <file_name> <32-bit in Hex> <Offset in Hex>", argv[0]);
exit(1);
}
off_t offset;
ssize_t nb_write;
int nb, n;
int fdin;
fdin = open(argv[1],O_WRONLY);
if (fdin == -1){
perror("File can't be opened");
exit(2);
}
offset = (off_t) strtol (argv[3], NULL, 16);
nb = (int) strtol(argv[2], NULL, 16);
n = lseek(fdin, offset * sizeof(int), SEEK_SET);
nb_write=write(fdin, &nb, sizeof(int));
printf("%x", nb);
return EXIT_SUCCESS;
}