dllbridge

fread sim

Aug 11th, 2026
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include   <stdio.h>
  5. #include  <stdlib.h>
  6. #include    <time.h>
  7. #include  <locale.h>       //  здесь "живёт" setlocale(LC_ALL, "rus");
  8.  
  9.  
  10. int get_X(int *p);
  11.  
  12. ////////////////////////////////////////////////////////
  13. int main()
  14. {
  15.    
  16.     setlocale(LC_ALL, "rus");
  17.    
  18.     srand(time(0));        
  19.    
  20.     int n, nCounter = 0;
  21.    
  22.    
  23.     while(get_X(&n) == 1)
  24.     {  
  25.         nCounter ++;
  26.         printf("%d, ", n);
  27.     }
  28.    
  29.     printf("\nФункция get_X смогла получить %d числа.\n", nCounter);
  30.  
  31. }
  32.  
  33. /////////////////////////////////////////////////////////////
  34. void monitor(int *p)
  35. {
  36.    
  37.      printf("Печатаем первые 20 элементов:\n");
  38.      for(int i = 0; i < 20; i++)
  39.      {
  40.            
  41.          printf("%d, ", p[i]);     
  42.      }   printf("\nРезультат вызовов функции get_X():\n");          //       printf("\n");
  43. }
  44.  
  45. /////////////////////////////////////////////////////////
  46. int get_X(int *p)
  47. {
  48.    
  49.     static int nArr[1000],
  50.             nCounter = 0;
  51.    
  52.     static int n = 20;//rand()%1000;                               //      Кол-во элементов
  53.    
  54.    
  55.     if(nCounter == 0)
  56.     {
  57.         for(int i = 0; i < n; i++) nArr[i] = rand();
  58.         printf("Массив проинициализирован! Всего %d элементов.\n", n);
  59.        
  60.         monitor(nArr);
  61.     }
  62.    
  63.     if(nCounter < n)
  64.     {
  65.        *p = nArr[nCounter];
  66.     }
  67.     else return 0;
  68.    
  69.     nCounter++;
  70.    
  71. return  1;
  72. }
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment