Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- int main(int argc, char *argv[])
- {
- char* input_file;
- char* stats_file;
- char* c = (char *) calloc(100, sizeof(char));
- char* buff = (char*) calloc(200, sizeof(char));
- int filedesc;
- int i, i_max;
- char option;
- int numar_majuscule = 0;
- int numar_cifre = 0;
- int hard_links = 0;
- int i_nodes = 0;
- int size = 0;
- int nbytes;
- struct stat fileStat;
- if (argc != 3 && argc != 4) {
- printf("EROARE BOSS");
- return 1;
- }
- input_file = argv[1];
- stats_file = argv[2];
- option = argv[3];
- if (option == 's'){
- unlink(input_file);
- symlink(input_file, stats_file);
- }
- if (option == 'h'){
- unlink(input_file);
- link (input_file, stats_file);
- }
- if(lstat(input_file,&fileStat) < 0)
- return 1;
- filedesc = open(input_file, O_RDONLY);
- if(filedesc < 0)
- return 1;
- hard_links = fileStat.st_nlink;
- i_nodes = fileStat.st_ino;
- size = fileStat.st_size;
- while(i_max = read(filedesc, c, 100)) {
- for(i=0; i<i_max; i++){
- if (c[i] >= 'A' && c[i] <= 'Z')
- numar_majuscule++;
- if (c[i] >= '0' && c[i] <= '9')
- numar_cifre++;
- }
- }
- close(filedesc);
- filedesc = open(stats_file, O_WRONLY);
- sprintf(buff, "Numarul de cifre: %d\nNumarul de majuscule: %d\nhard_links: %d\ni_nodes: %d\nsize: %d", numar_cifre, numar_majuscule, hard_links, i_nodes, size);
- nbytes = strlen(buff);
- write(filedesc, buff, nbytes);
- close(filedesc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement