Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- #include "unistd.h"
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <ctype.h>
- #define blocksize 4096
- int main(int argc, char *argv[]){
- char *file, *dir, *outfile;
- if(argc != 3){
- printf("Usage: %s file dir",argv[0]);
- exit(-2);
- }
- else{
- file = (char*)malloc(sizeof(char)*strlen(argv[1])+1);
- outfile = (char*)malloc(sizeof(char)*(strlen(argv[1])+strlen(argv[2]))+1);
- dir = (char*)malloc(sizeof(char)*strlen(argv[2])+1);
- strcpy(file,argv[1]);
- strcpy(dir,argv[2]);
- strcat(outfile,dir);
- strcat(outfile,file);
- }
- float procent, majuscule = 0, litere = 0;
- char buffer[blocksize], bufferout[blocksize];
- int finp = open(file,O_RDONLY);
- int fout = open(outfile,O_WRONLY|O_CREAT,S_IWUSR|S_IRUSR);
- int readval;
- while(1){
- readval = read(finp, buffer, blocksize);
- litere+=readval;
- for(int i = 0; i < readval; i++)
- if(isupper(buffer[i]))
- majuscule++;
- if(readval != blocksize)
- break;
- }
- procent = majuscule/litere*100;
- struct stat *struct_buf;
- struct_buf = (struct stat*)malloc(sizeof(struct stat));
- stat(argv[0],struct_buf);
- sprintf(bufferout,"Procentul este %f\%; UID = %u\n",procent,struct_buf->st_uid);
- printf("%s",bufferout);
- write(fout,bufferout,strlen(bufferout));
- if(symlink(outfile,"mylink")!=0)
- exit(-3);
- close(finp);
- close(fout);
- free(file);
- free(dir);
- free(outfile);
- free(struct_buf);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement