|
-
February 19th, 2009, 07:38 PM
#1
Question re: fread/fwrite
hello all,
I have a unsigned char 1d array of size_x, let's call it Array1. (It contains information on intensity of a grey scale graph). Before saving it to a file, i can go Array1[245] and obtain the intensity value at that position of the array. Then I save it this way:
FILE * the_file;
the_file = fopen(filename,"w+b")
fwrite(Array1,sizeof(unsigned char),size_x,the_file);
so now the saved file should contain all these information right?
then I tried to read the same file back
unsigned char * read_mat;
file_read = fopen(filename, "rb" );
fseek (file_read , 0 , SEEK_END);
file_size = ftell (file_read);
rewind (file_read);
read_mat = new unsigned char[file_size];
fread(read_mat,sizeof(unsigned char),file_size,file_read);
now should the read_mat array contain the same information as Array1 the one i used to save my file with?
because I tried to just read a random number from read_mat[] but it always gives me zero.
..this is one way i did:
CString temp_text;
for (int i=0;i<file_size;i++)
{
int temp_num=(int)read_mat[i];
temp_text.Format("int is %d",temp_num);
MessageBox(temp_text);
}
did something go wrong with saving? or something go wrong with reading?
the file I saved shows the expected size.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|