I want to read characters(256 of them) from a file and put thier numeric value in an array.Then i want to send 16 characters in batches from the array onto a loop in successive steps to perform operations on them.
My problem:
First i can read the first batch of 16 characters easily. But after the second or third it starts showing 0,32 or 255 as the characters,but there are no spaces and it does not read the character but just fills it with blanks.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int size=0;
int ff=0,ww=0,g=0,h=0,l=0;
char cc[256];
int a[256];
ifstream infile;
ofstream myfile;
infile.open("as86.txt",ios::binary);
infile.get(cc,257);
infile.close();
}
cout <<< endl;
do
{
h=g+16;
for(int i=g;i<h;i++){
a[i] = (unsigned char)cc[i];
cout << a[i] << " ";
}
g=h;
l++;
}
while(l<=15);
Now unfortuantely it only prints about thew first 32-35 characters properly,after that it goes haywire.
What's wrong ? Any better ways to read character from file and send thier numeric value into an array.
Thanks.