Guest User

Untitled

a guest
Jan 22nd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <curl/curl.h>
  5.  
  6. int ile_razy = 0;
  7.  
  8. int progress_func(void* ptr, double TotalToDownload, double NowDownloaded,
  9. double TotalToUpload, double NowUploaded)
  10. {
  11.  
  12. int totaldotz=40;
  13. double fractiondownloaded = NowDownloaded / TotalToDownload;
  14.  
  15. int dotz = round(fractiondownloaded * totaldotz);
  16.  
  17.  
  18. int ii=0;
  19. printf("%3.0f%% [",fractiondownloaded*100);
  20.  
  21. for ( ; ii < dotz;ii++) {
  22. printf("=");
  23. }
  24.  
  25. for ( ; ii < totaldotz;ii++) {
  26. printf(" ");
  27. }
  28.  
  29. printf("] %d razy \r", ile_razy);
  30. fflush(stdout);
  31. }
  32.  
  33.  
  34. int main(int argc, char *argv[])
  35. {
  36.  
  37. if (argc<3)
  38. {
  39. printf("sposob uzycia programu:\n\n download link_do_pliku ilosc_pobran\n\n");
  40. return 0;
  41. }
  42.  
  43.  
  44.  
  45. CURL *curl;
  46. CURLcode res;
  47.  
  48. curl = curl_easy_init();
  49. if(curl)
  50. {
  51.  
  52. curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
  53. // curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
  54. curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
  55. curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func);
  56.  
  57.  
  58. FILE *out = NULL;
  59.  
  60. int i=0;
  61. int loop = atoi(argv[2]);
  62.  
  63. // int loop = 1500;
  64.  
  65. for (i=0; i<loop; i++)
  66. {
  67. // printf("Zadanie wykonano %d razy. \r", ile_razy);
  68. // fflush(stdout);
  69.  
  70. out = fopen("temp", "wb");
  71. curl_easy_setopt(curl, CURLOPT_WRITEDATA, out);
  72. res = curl_easy_perform(curl);
  73. ile_razy++;
  74. fclose(out);
  75. }
  76.  
  77. curl_easy_cleanup(curl);
  78.  
  79. }
  80.  
  81. printf("\nwykonano: %d razy. \n", ile_razy);
  82.  
  83. return 0;
  84. }
Add Comment
Please, Sign In to add comment