Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <string.h>
- #include <linux/random.h>
- #include <math.h>
- int main( int argc, char** argv) {
- int c = 0;
- int bvalue = 64;
- FILE *file;
- char **wsk = NULL;
- while (optind < argc) {
- if ((c = getopt(argc, argv, "b:")) != -1) {
- switch (c) {
- case 'b':
- bvalue = strtol(optarg, wsk, 0);
- break;
- default:
- printf("Usage: %s -b (optional)<count> <path>\n", argv[0]);
- break;
- }
- } else {
- file = open(argv[optind], O_RDONLY);
- if (file == -1) {
- printf("Can't open a file!\n");
- return 1;
- }
- optind++;
- }
- }
- double numbers[65536];
- int i=0;
- ssize_t result=0;
- do {
- char buf[8];
- result += read(file, buf, sizeof(buf));
- numbers[i]=*((double*)buf);
- i++;
- }while(result+8<=32768);
- for(int k = 0; k < 10; k++)
- printf("%lf\n", numbers[k]);
- /*
- char buf[sizeof(double)];
- double max = 127;
- double min = -128;
- int i = 0;
- int przedzial[bvalue];
- memset(przedzial, 0, bvalue * sizeof(int));
- int k;
- while( read(file, buf, sizeof(double)) )
- {
- double liczba = strtod*buf;
- liczba = liczba + 128;
- max -= min;
- min = 0;
- k = (int) (liczba / ((max-min)/bvalue));
- przedzial[k]++;
- i++;
- }
- printf("#cnt %d\n", i);
- printf("#bins %d\n", bvalue);
- for( int k = 0; k < bvalue; k++)
- printf("%d: %d\n", k, przedzial[k]);
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement