Advertisement
jacknpoe

Loopexe e Dorme

Nov 2nd, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. —————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  2. LOOPEXE.CPP
  3. —————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  4.  
  5. #include <windows.h>
  6. #include <cstdlib>
  7. #include <iostream>
  8.  
  9. int main( int argc, char* argv[])
  10. {
  11.     int retorno;
  12.  
  13.     if( argc < 2) exit( 1);     // sem parâmetro
  14.  
  15.     while( true) {
  16.         retorno = system( argv[ 1]);
  17.  
  18.         std::cout << "\nRetorno: " << retorno << "\n\n";
  19.         Sleep( 1000);
  20.     }
  21.        
  22.     return 0;
  23. }
  24.  
  25.  
  26. —————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  27. DORME.CPP
  28. —————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  29.  
  30. #include <windows.h>
  31. #include <time.h>
  32. #include <sstream>
  33. #include <iostream>
  34.  
  35. int main( int argc, char* argv[])
  36. {
  37.     time_t tempo1, tempo2;
  38.     long diferenca = 0, TEMPOTOTAL = 10, TEMPOSLEEP = 1;
  39.  
  40.     if( !( argc < 2)) std::istringstream ( argv[ 1]) >> TEMPOTOTAL;  // primeiro parâmetro, tempo total em segundos
  41.     if( !( argc < 3)) std::istringstream ( argv[ 2]) >> TEMPOSLEEP;  // segundo parámetro, intervalo em segundos
  42.     std::cout << "Dorme " << TEMPOTOTAL << " segundos em intervalo de " << TEMPOSLEEP << " segundos\n\n";
  43.  
  44.     tempo2 = tempo1 = time( NULL);
  45.  
  46.     while( diferenca < TEMPOTOTAL)
  47.     {
  48.         std::cout << diferenca << " segundos\n";
  49.         Sleep( TEMPOSLEEP * 1000);
  50.         tempo2 = time( NULL);
  51.         diferenca = difftime( tempo2, tempo1);
  52.     }
  53.  
  54.     std::cout << "\n";
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement