1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
main(int argc,char *argv[])
{
int filedes;
char inbuf[512];
char outbuf[512];
printf("Texte\n");
char text[200];
scanf("%s",text);
printf("Ouverture\n");
filedes=open("verseruveur",O_RDWR);
if(filedes==-1)
{
printf("erreur ouverture en ecriture: open \n");
exit(1);
}
strncpy(outbuf,text,sizeof(outbuf));
printf("Ecriture\n");
write(filedes, outbuf, sizeof(outbuf));
printf("message ecrit: %s\n",inbuf);
printf("Lecture\n");
read(filedes, inbuf, sizeof(inbuf));
printf("message lu: %s\n",inbuf);
close(filedes);
exit(0);
} |
Partager