This commit is contained in:
Adrian POURCHOT 2023-03-30 11:18:50 +02:00
parent 7566b70d78
commit 64fb4d9c0b
6 changed files with 54 additions and 1 deletions

37
SCR1.2/TP11/get_numb.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define SZBUF 256
int main(int argc, char const *argv[]){
int fd,n,l,x;
long int i, offset;
if (argc<3){
fprintf(stderr,"Usage : %s <file_name> <offset> \r",argv[0]);
exit (1);
} fd=open (argv[1], O_RDONLY);
if (fd==-1){
perror("Opening destination file fails");
exit (2);
} i=strtol(argv[2],NULL,0);
offset=i*(sizeof(int));
l=lseek(fd,offset,SEEK_SET);
if(l==1){
perror("lsink failed");
close(fd);
exit (3);
}
n=read(fd,&x,sizeof(int));
if(n==-1){
perror("Read in file failed");
close(fd);
exit (4);
} if(n==0){
printf("Out of range\n");
} else{
printf("The number at offset %ld is 0x%08x --> %d \n",i,x,x);
} close(fd);
exit(0);
}

16
SCR1.2/TP11/put_numb.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define SZBUF 256
int main(int argc, char const *argv[]){
char buf[SZBUF];
int fd,n,m;
if (argc<4){
fprintf(stderr,"Usage : %s <file_name> <32-bit int in Hex> <Offset in Hex> \r",argv[0]);
exit (1);
}
}

Binary file not shown.

View File

@ -9,7 +9,7 @@ int main(int argc, char const *argv[]){
char buf[SZBUF];
int fd,n,m;
if (argc<2){
fprintf(stderr,"Usage : %s <bSR_FILE> \r",argv[0]);
fprintf(stderr,"Usage : %s <SR_FILE> \n",argv[0]);
exit (1);
} fd=open (argv[1], O_WRONLY|O_TRUNC|O_CREAT,0b00);
if (fd==-1){

BIN
SCR1.2/TP14/ft-file.dat Normal file

Binary file not shown.

0
SCR1.2/TP15/reponses.txt Normal file
View File