Creato programma che usando i file legge il file sample e lo ricopia in sample_copied contando righe,vocali,numeri e caratteri
This commit is contained in:
BIN
4.file_read_count/copycount
Executable file
BIN
4.file_read_count/copycount
Executable file
Binary file not shown.
87
4.file_read_count/copycount.c
Normal file
87
4.file_read_count/copycount.c
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main (int index, char** in_data){
|
||||||
|
|
||||||
|
|
||||||
|
int fd,fd2,ridden,wrote, tot,vocali,cifre,righe;
|
||||||
|
tot = vocali = cifre = righe = 0;
|
||||||
|
char buf;
|
||||||
|
fd = open ("sample",O_RDONLY);
|
||||||
|
fd2 = open ("sample_copied", O_CREAT | O_WRONLY,00700);
|
||||||
|
if (fd < 0){
|
||||||
|
fprintf(stderr,"Error reading file %d\n",errno);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
if (fd2 < 0){
|
||||||
|
fprintf(stderr,"Error creating file %d\n",errno);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ridden = read (fd,&buf,1) ; ridden == 1 ;ridden = read (fd,&buf,1)){
|
||||||
|
|
||||||
|
|
||||||
|
if (isdigit(buf) != 0){
|
||||||
|
cifre++; tot++;
|
||||||
|
wrote = write (fd2,&buf,1);
|
||||||
|
if (wrote != 1){
|
||||||
|
fprintf(stderr,"Error writing to file %d\n",errno);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf == 'a' || buf == 'e' || buf == 'i' || buf == 'o' || buf == 'u'){
|
||||||
|
vocali++;tot++;
|
||||||
|
wrote = write (fd2,&buf,1);
|
||||||
|
if (wrote != 1){
|
||||||
|
fprintf(stderr,"Error writing to file %d\n",errno);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf == '\n'){
|
||||||
|
righe++;tot++;
|
||||||
|
wrote = write (fd2,&buf,1);
|
||||||
|
if (wrote != 1){
|
||||||
|
fprintf(stderr,"Error writing to file %d\n",errno);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tot++;
|
||||||
|
wrote = write (fd2,&buf,1);
|
||||||
|
if (wrote != 1){
|
||||||
|
fprintf(stderr,"Error writing to file %d\n",errno);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ridden < 0){
|
||||||
|
fprintf(stderr,"Error reading file %d\n",errno);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stdout, "Numero vocali %d\n", vocali);
|
||||||
|
fprintf (stdout, "Numero righe %d\n", righe);
|
||||||
|
fprintf (stdout, "Numero cifre %d\n", cifre);
|
||||||
|
fprintf (stdout, "Numero caratteri %d\n", tot);
|
||||||
|
|
||||||
|
close(fd);close(fd2);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
1
4.file_read_count/readme.txt
Normal file
1
4.file_read_count/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
il programma legge il file sample e lo ricopia in sample_copied contango righe,vocali,numeri e caratteri
|
||||||
6
4.file_read_count/sample
Normal file
6
4.file_read_count/sample
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aafdsfdsfdfdfdfdf
|
||||||
|
4343
|
||||||
|
fdsd342
|
||||||
|
fdfdsfFJSNJNDJS
|
||||||
|
dfdsfa
|
||||||
|
|
||||||
6
4.file_read_count/sample_copied
Executable file
6
4.file_read_count/sample_copied
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
aafdsfdsfdfdfdfdf
|
||||||
|
4343
|
||||||
|
fdsd342
|
||||||
|
fdfdsfFJSNJNDJS
|
||||||
|
dfdsfa
|
||||||
|
|
||||||
6
4.file_read_count/sample~
Normal file
6
4.file_read_count/sample~
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
fdsfdsfdfdfdfdf
|
||||||
|
4343
|
||||||
|
fdsd342
|
||||||
|
fdfdsfFJSNJNDJS
|
||||||
|
dfdsf
|
||||||
|
|
||||||
Reference in New Issue
Block a user