Advertisement
abs25

LV-13 - Fix

Jan 6th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <random>
  5.  
  6. using namespace std;
  7.  
  8. template <typename dataType>
  9. static dataType RNG(dataType from, dataType to)
  10. {
  11.     random_device rd;                                           // better source of seeds than time()
  12.     mt19937 gen(rd());                                          // seed Mersenne Twister
  13.     uniform_int_distribution<> rand(from, to);                  // range of numbers
  14.  
  15.     return rand(gen);
  16. }
  17.  
  18. int main(void)
  19. {
  20.     //printf("//==================\\ ZADATAK [1] //==================\\\n");
  21.     //int *a, br, nm = 100, nv = -100;
  22.  
  23.     //printf("Unesize zeljenu velicinu polja: ");
  24.     //scanf("%d", &br);
  25.  
  26.     //a = (int *)malloc(br*sizeof(int));
  27.     //if (a == NULL)
  28.     //  return 1;
  29.  
  30.     //for (size_t i = 0; i < br; i++)
  31.     //{
  32.     //  a[i] = RNG<int>(-100, 100);
  33.     //  if (a[i] < nm)
  34.     //      nm = a[i];
  35.     //  if (a[i] > nv)
  36.     //      nv = a[i];
  37.     //}
  38.     //printf("najveci je %d, a najmanji %d\n\n", nv, nm);
  39.     //free(a);
  40.     //printf("//====================================================\\\n");
  41.  
  42.     //printf("\n//==================\\ ZADATAK [2] //==================\\\n");
  43.     //double *b;
  44.     //int rand = RNG(50, 100);
  45.     //
  46.     //b = (double *)malloc(br*sizeof(double));
  47.     //if (b == NULL)
  48.     //  return 1;
  49.  
  50.     //for (size_t i = 0; i < rand; i++)
  51.     //{
  52.     //  double c= 0.0, d = 1.0;
  53.     //  b[i] = RNG<double>(c,d);
  54.     //  if (b[i] == 1)
  55.     //      printf("b[%d] == 1 \n", i);
  56.     //}
  57.     //free(b);
  58.     //printf("//====================================================\\\n");
  59.  
  60.  
  61.     printf("\n//==================\\ ZADATAK [3] //==================\\\n");
  62.  
  63.     int length = 0, space = 0;
  64.     char *str;
  65.    
  66.     while (length > 1 && length < 500);
  67.     {
  68.         printf("Unesite zeljenu duljinu stringa ");
  69.         scanf_s("%d", &length);
  70.     }
  71.     fseek(stdin, 0, SEEK_END);
  72.     str = (char *)malloc((length)*sizeof(char));
  73.     if (str == NULL)
  74.         return NULL;
  75.  
  76.     printf_s("\nUnesite %d, znakova u string: ", length);
  77.     do{
  78.         fgets(str, length, stdin);
  79.     } while (strlen(str) <= 1 && strlen(str) >= length);
  80.  
  81.     for (size_t i = 0; i < strlen(str); i++)
  82.     {
  83.         if (str[i] ==' ')
  84.             space++;
  85.     }
  86.     printf("\Broj razmaka iznosi: %d ", space);
  87.     free(str);
  88.     printf("//====================================================\\\n");
  89.  
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement