#include<iostream>
#include<fstream>
#define TRANSFORMS 4
#define BLOCK 4
using namespace std;
char* img=new char[128*128*TRANSFORMS];
int main(){
ifstream File;
File.open("ficdata");
int isize=128*TRANSFORMS*128;
int inc=TRANSFORMS*128;
int jsize=128*TRANSFORMS;
int i=0,j=0,temp;
while(!File.eof())
{
File>>temp;
img[i+j]=temp;
j+=TRANSFORMS;
if(j==jsize){
j=0;
i+=inc;
}
if(i==isize){
break;
}
}
for(int i=0;i<isize;i+=inc){
for(int j=0;j<jsize;j+=TRANSFORMS){
cout<<(int)img[i+j]<<" ";
}
}
}
In the above code snippet the file contains 128*128 values which are between 0-255.When I try to typecast the values back to int and print them I get some values as positive and some values as negative.Why does that happen?The int values are getting stored properly and the problem occurs only when typecasting them back.