Advertisement
Guest User

Untitled

a guest
May 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void main()
  5. {
  6.     unsigned short arrayf[900];
  7.     int freq[65536] = { 0 };
  8.     int i = 0, j = 0;
  9.     FILE *  fo;
  10.  
  11.     fo = fopen("C:\\162836Z\\ArrayF.bin", "rb");
  12.     if (fo == NULL)
  13.         printf("Error opening file");
  14.     else
  15.     {
  16.         printf("Successfully loaded\n");
  17.         //read data from bin file
  18.         if (fread(arrayf, sizeof(unsigned short), 900, fo) != 900)
  19.         {
  20.             printf("Error reading into binfile");
  21.         }
  22.         else
  23.         {
  24.             for (i = 0; i < 900; i++)
  25.             {
  26.                 j = arrayf[i];
  27.                 freq[j]++;
  28.             }
  29.  
  30.             for (i = 0; i < 65536; i++)
  31.             {
  32.                 if (freq[i] != 0)
  33.                 printf("%d , %d\n", i , freq[i]);
  34.             }
  35.         }
  36.         fclose(fo);
  37.     }
  38.  
  39.     fo = fopen("C:\\162836Z\\ArrayF.txt", "wt");
  40.     if (fo == NULL)
  41.         printf("Error opening file");
  42.     else
  43.     {
  44.         printf("Successfully loaded\n");
  45.         //write data into txt file
  46.         for (i = 0; i < 65536; i++)
  47.         {
  48.             if (freq[i] != 0)
  49.             fprintf(fo, "%d , %d\n", i, freq[i]);
  50.         }
  51.         fclose(fo); //close file
  52.     }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.     getchar();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement