Ajout de travaux
This commit is contained in:
137
23SCR/SCR011/SCR011.txt
Normal file
137
23SCR/SCR011/SCR011.txt
Normal file
@@ -0,0 +1,137 @@
|
||||
1/
|
||||
meme chose avec write(1);
|
||||
|
||||
2/
|
||||
#include<stdio.h>
|
||||
#include<fcntl.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
#define szbuf 256
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char buf[szbuf];
|
||||
int f1,f2,n,m;
|
||||
if(argc<3)
|
||||
{
|
||||
fprintf(stderr, "Usage : %s <SRC.FILE><TRUC.FILE>",argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
f1 = open(argv[1],O_RDONLY);
|
||||
if(f1 == -1)
|
||||
{
|
||||
perror("Opening source file fails");
|
||||
exit(2);
|
||||
}
|
||||
f2 = open(argv[2],O_WRONLY|O_TRUNC|O_CREAT,0600);
|
||||
if(f2 == -1)
|
||||
{
|
||||
perror("Opening destination file fails");
|
||||
exit(3);
|
||||
}
|
||||
while(n = read(f1,buf,szbuf))
|
||||
{
|
||||
m = write(f2,buf,n);
|
||||
if(m == -1)
|
||||
{
|
||||
perror("Writing in file fails");
|
||||
exit(4);
|
||||
}
|
||||
}
|
||||
close(f1);
|
||||
close(f2);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
3/
|
||||
#include<stdio.h>
|
||||
#include<fcntl.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define szbuf 256
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char buf[szbuf];
|
||||
int a, b, c, d;
|
||||
if(argc<2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s ./store_numb <file_name>",argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
a = open(argv[1],O_WRONLY|O_TRUNC|O_CREAT,0600);
|
||||
if(a == -1)
|
||||
{
|
||||
perror("Opening destination file fails");
|
||||
exit(2);
|
||||
}
|
||||
b = open(argv[2],O_WRONLY|O_TRUNC|O_CREAT,0600);
|
||||
if(b == -1)
|
||||
{
|
||||
perror("Opening destination file fails");
|
||||
exit(3);
|
||||
}
|
||||
write(1,"Numb --> ",9);
|
||||
memset(buf,0,szbuf);
|
||||
while(b = read(0,buf,szbuf))
|
||||
{
|
||||
d = (int)strtol(buf,NULL,0);
|
||||
c = write(a,&d,sizeof(int));
|
||||
if(c == -1)
|
||||
{
|
||||
perror("Writing in file fails");
|
||||
exit(3);
|
||||
}
|
||||
memset(buf,0,szbuf);
|
||||
write(1,"Numb --> ",9);
|
||||
}
|
||||
close(a);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
4/
|
||||
#include<stdio.h>
|
||||
#include<fcntl.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define szbuf 256
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char buf[szbuf];
|
||||
int a, b, c, d;
|
||||
if(argc<2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s ./store_numb <file_name>",argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
a = open(argv[1],O_WRONLY|O_TRUNC|O_CREAT,0600);
|
||||
if(a == -1)
|
||||
{
|
||||
perror("Opening destination file fails");
|
||||
exit(2);
|
||||
}
|
||||
write(1,"Numb --> ",9);
|
||||
memset(buf,0,szbuf);
|
||||
while(b = read(0,buf,szbuf))
|
||||
{
|
||||
d = (int)strtol(buf,NULL,0);
|
||||
c = write(a,&d,sizeof(int));
|
||||
if(c == -1)
|
||||
{
|
||||
perror("Writing in file fails");
|
||||
exit(3);
|
||||
}
|
||||
memset(buf,0,szbuf);
|
||||
write(1,"Numb --> ",9);
|
||||
}
|
||||
close(a);
|
||||
exit(0);
|
||||
}
|
||||
BIN
23SCR/SCR011/a.out
Executable file
BIN
23SCR/SCR011/a.out
Executable file
Binary file not shown.
49
23SCR/SCR011/get_numb.c
Normal file
49
23SCR/SCR011/get_numb.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include<stdio.h>
|
||||
#include<fcntl.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
|
||||
#define szbuf 256
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char buf[szbuf];
|
||||
int fd, l, n, x;
|
||||
long int i, offset;
|
||||
if(argc<3)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s ./get_numb <file_name> <offset>",argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
fd = open(argv[1],O_RDONLY);
|
||||
if(fd == -1)
|
||||
{
|
||||
perror("Opening file fails");
|
||||
exit(2);
|
||||
}
|
||||
i = strtol(argv[2],NULL,0);
|
||||
offset = i* sizeof(int);
|
||||
l = lseek(fd,offset,SEEK_SET);
|
||||
if(l == -1)
|
||||
{
|
||||
perror("lseek fails");
|
||||
exit(3);
|
||||
}
|
||||
n = read(fd,&x,sizeof(int));
|
||||
if(n ==-1)
|
||||
{
|
||||
perror("road in file fails");
|
||||
exit(4);
|
||||
}
|
||||
if(n == 0)
|
||||
{
|
||||
printf("Offset is out of range!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("The number at offset %d is 0x%08e --> %d\n",i,x,x);
|
||||
}
|
||||
close(fd);
|
||||
exit(0);
|
||||
}
|
||||
BIN
23SCR/SCR011/numbers.dat
Normal file
BIN
23SCR/SCR011/numbers.dat
Normal file
Binary file not shown.
0
23SCR/SCR011/numbers.txt
Normal file
0
23SCR/SCR011/numbers.txt
Normal file
46
23SCR/SCR011/put_numb.c
Normal file
46
23SCR/SCR011/put_numb.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include<stdio.h>
|
||||
#include<fcntl.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define szbuf 256
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char buf[szbuf];
|
||||
int a, b, c, d;
|
||||
if(argc<2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s ./store_numb <file_name>",argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
a = open(argv[1],O_WRONLY|O_TRUNC|O_CREAT,0600);
|
||||
if(a == -1)
|
||||
{
|
||||
perror("Opening destination file fails");
|
||||
exit(2);
|
||||
}
|
||||
b = open(argv[2],O_WRONLY|O_TRUNC|O_CREAT,0600);
|
||||
if(b == -1)
|
||||
{
|
||||
perror("Opening destination file fails");
|
||||
exit(3);
|
||||
}
|
||||
write(1,"Numb --> ",9);
|
||||
memset(buf,0,szbuf);
|
||||
while(b = read(0,buf,szbuf))
|
||||
{
|
||||
d = (int)strtol(buf,NULL,0);
|
||||
c = write(a,&d,sizeof(int));
|
||||
if(c == -1)
|
||||
{
|
||||
perror("Writing in file fails");
|
||||
exit(3);
|
||||
}
|
||||
memset(buf,0,szbuf);
|
||||
write(1,"Numb --> ",9);
|
||||
}
|
||||
close(a);
|
||||
exit(0);
|
||||
}
|
||||
41
23SCR/SCR011/read_file.c
Normal file
41
23SCR/SCR011/read_file.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include<stdio.h>
|
||||
#include<fcntl.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
#define szbuf 256
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char buf[szbuf];
|
||||
int f1,f2,n,m;
|
||||
if(argc<3)
|
||||
{
|
||||
fprintf(stderr, "Usage : %s <SRC.FILE><TRUC.FILE>",argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
f1 = open(argv[1],O_RDONLY);
|
||||
if(f1 == -1)
|
||||
{
|
||||
perror("Opening source file fails");
|
||||
exit(2);
|
||||
}
|
||||
f2 = open(argv[2],O_WRONLY|O_TRUNC|O_CREAT,0600);
|
||||
if(f2 == -1)
|
||||
{
|
||||
perror("Opening destination file fails");
|
||||
exit(3);
|
||||
}
|
||||
while(n = read(f1,buf,szbuf))
|
||||
{
|
||||
m = write(f2,buf,n);
|
||||
if(m == -1)
|
||||
{
|
||||
perror("Writing in file fails");
|
||||
exit(4);
|
||||
}
|
||||
}
|
||||
close(f1);
|
||||
close(f2);
|
||||
exit(0);
|
||||
}
|
||||
39
23SCR/SCR011/store_nb_rep.c
Normal file
39
23SCR/SCR011/store_nb_rep.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include<stdio.h>
|
||||
#include<fcntl.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define szbuf 256
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char buf[szbuf];
|
||||
int fd,x;
|
||||
off-t l;
|
||||
unsigned int x;
|
||||
long int i, offset;
|
||||
if(argc<4)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s ./get_numb <file_name> <offset>",argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
fd = open(argv[1],O_RDONLY);
|
||||
if(fd == -1)
|
||||
{
|
||||
perror("Opening file fails");
|
||||
exit(2);
|
||||
}
|
||||
x = (unsigned int) strtol(argv[2],NULL,16);
|
||||
i = (unsigned int) strtol(argv[3],NULL,16);
|
||||
offset = i x sizeof(int);
|
||||
l = lseek(fd,0,SEEK_SET);
|
||||
if(l == -1)
|
||||
{
|
||||
close(fd);
|
||||
exit(3);
|
||||
}
|
||||
close(a);
|
||||
exit(0);
|
||||
}
|
||||
30
23SCR/SCR011/store_numb.c
Normal file
30
23SCR/SCR011/store_numb.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include<stdio.h>
|
||||
#include<fcntl.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
#define szbuf 256
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char buf[szbuf];
|
||||
int f1,f2,n,m;
|
||||
if(argc<2)
|
||||
{
|
||||
fprintf(stderr, "Usage : %s <file_name>",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
fd = open(argv[1],O_WRONLY|O_TRUNC|O_CREAT,0600);
|
||||
if(fd == -1)
|
||||
{
|
||||
perror("Opening source file fails");
|
||||
exit(2);
|
||||
}
|
||||
write (1, "Numb---> ", 9);
|
||||
while(n = read (0, buf, szbuf)){
|
||||
m = write (fd, buf, n);
|
||||
if
|
||||
}
|
||||
close(fd);
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user