APL/APL1.2/SCR1.2/TP11/put_numb.c

36 lines
877 B
C
Raw Normal View History

2022-01-25 12:47:42 +01:00
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>
int main(int argc, char* argv[]) {
2022-02-07 10:53:37 +01:00
int f,n;
unsigned int x;
unsigned long int i, offset, l;
2022-01-25 12:47:42 +01:00
memset(tst,0,256);
2022-02-07 10:53:37 +01:00
if(argc<4){
2022-01-25 12:47:42 +01:00
printf("erreur : %s <file_name> <32-bit int in Hex> <Offset in Hex>\n",argv[0]);
exit(1);
}
2022-02-07 10:53:37 +01:00
f=open(argv[1],O_WRONLY);
if(f==-1){
perror("Opening failed");
exit(2);
}
x= (unsigned int)strtol(argv[2],NULL,16);
i= (unsigned int)strtol(argv[3],NULL,16);
offset = i*sizeof(int);
l=lseek(f,0,SEEK_END);
if (offset > l) offset =l;
l=lseek(f,offset,SEEK_SET);
2022-01-25 12:47:42 +01:00
if(l==-1){
perror("erreur dans lseek");
exit(2);
2022-02-07 10:53:37 +01:00
}
2022-01-25 12:47:42 +01:00
ents = strtol(argv[2],NULL,16);
2022-02-07 10:53:37 +01:00
write(f,&x,sizeof(int));
close(f);
2022-01-25 12:47:42 +01:00
return EXIT_SUCCESS;
}