Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "time.h"
  4.  
  5.  
  6. int main(int argc, char** args){
  7.      
  8.      srand( time( NULL ) );
  9.      
  10.     if(argc < 3){
  11.         printf("Złe uzycie programu, podaj 3 parametry");
  12.         return -1;
  13.     }
  14.    
  15.     float t = (float)atof(args[0]);
  16.     char* s = args[1];
  17.     int d = atoi(args[2]);
  18.    
  19.     struct timespec ts;
  20.     ts.tv_sec = (int)t;
  21.     ts.tv_nsec = (t - (int)t) * 1000000000;
  22.  
  23.    
  24.     while(1){
  25.        
  26.         nanosleep(&ts, NULL);
  27.         write(d, s, strlen(args[1]);
  28.        
  29.         if(rand()%2 == 0){
  30.            
  31.             return 0;
  32.         }
  33.        
  34.     }
  35.    
  36.    
  37.    
  38.    
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement