Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <string.h>
  6. #include <linux/random.h>
  7. #include <math.h>
  8.  
  9. int main( int argc, char** argv) {
  10. int c = 0;
  11. int bvalue = 64;
  12. FILE *file;
  13. char **wsk = NULL;
  14.  
  15. while (optind < argc) {
  16. if ((c = getopt(argc, argv, "b:")) != -1) {
  17. switch (c) {
  18. case 'b':
  19. bvalue = strtol(optarg, wsk, 0);
  20. break;
  21.  
  22. default:
  23. printf("Usage: %s -b (optional)<count> <path>\n", argv[0]);
  24. break;
  25. }
  26. } else {
  27. file = open(argv[optind], O_RDONLY);
  28. if (file == -1) {
  29. printf("Can't open a file!\n");
  30. return 1;
  31. }
  32. optind++;
  33. }
  34. }
  35.  
  36.  
  37. double numbers[65536];
  38. int i=0;
  39. ssize_t result=0;
  40. do {
  41. char buf[8];
  42. result += read(file, buf, sizeof(buf));
  43. numbers[i]=*((double*)buf);
  44. i++;
  45. }while(result+8<=32768);
  46.  
  47. for(int k = 0; k < 10; k++)
  48. printf("%lf\n", numbers[k]);
  49.  
  50.  
  51. /*
  52. char buf[sizeof(double)];
  53. double max = 127;
  54. double min = -128;
  55. int i = 0;
  56.  
  57. int przedzial[bvalue];
  58. memset(przedzial, 0, bvalue * sizeof(int));
  59.  
  60. int k;
  61. while( read(file, buf, sizeof(double)) )
  62. {
  63. double liczba = strtod*buf;
  64. liczba = liczba + 128;
  65. max -= min;
  66. min = 0;
  67.  
  68. k = (int) (liczba / ((max-min)/bvalue));
  69. przedzial[k]++;
  70.  
  71. i++;
  72. }
  73.  
  74. printf("#cnt %d\n", i);
  75. printf("#bins %d\n", bvalue);
  76.  
  77. for( int k = 0; k < bvalue; k++)
  78. printf("%d: %d\n", k, przedzial[k]);
  79.  
  80. */
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement