-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwr_file.c
24 lines (22 loc) · 839 Bytes
/
wr_file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#define N 1000
int main(int argc, char const *argv[]) {
int file= open(argv[1], O_RDWR | O_CREAT); /*O_RDWR specifica che il file è aperto in lettura e scrittura,
O_CREAT che il file viene creato se non preesiste. Il valore
restituito da open() è un descrittore intero del file*/
if (file==-1) perror("Creazione file fallita");
else {
char charbuf[1]="a";
for (int i=1; i<=N; i++) {
int w= write(file, charbuf, 1); //viene scritto un byte per volta (III parametro di write())
if (w==-1) perror("Scrittura fallita.");
}
close(file);
}
return 0;
}