Code:
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
char signed_character;
unsigned char byte;
unsigned int numberofbytes;
int i, num=0, number=0;
int numarray[262143];
int main()
{
ifstream file("Binary File", ios::in||ios::binary);
while (file.get(signed_character))
{
byte =(unsigned char) signed_character;
numarray[i]=byte;
numberofbytes++;
i++;
}
sort(numarray, numarray+262143);
for (i=0;i!=262143;i++)
{
if(number==numarray[i])
{
num++;
}
else
{
cout<<"There are "<<num<<" "<<number<<" s in this file \n";
i--;
number++;
num=0;
}
}
return 0;
}
This code Reads in a binary file, counts up the number of binary 1s,2s,3s,4s.....255s and displays them on screen, the only problem is it doesnt count and display the number of binary 255s, it only goes up to 254!!
Anyone able to give me a clue of why its doing this??
Thanks