   Can't get desired data value from array
  part of the code, reading an image file into memory--------------------------------------------------------unsigned char Picture[Size][Size][BytesPerPixel];if (!(file=fopen(argv[1],"rb"))) {cout << "Cannot open picture: " << argv[1] <<endl;exit(1);}fread(Picture, sizeof(unsigned char), Size*Size*BytesPerPixel, file);fclose(file);---------------------------------------------------------when i tryied to get the value of the 1st element in Picture, i put cout << Picture[0][0][0] << endl; after fread(.... before flose(file); ,it turned out to be nothing printed on my WinXP command prompt. However, the image file was stored successfully because i got the desired image after end of execution(store pic and spit out the exact same pic). the problem is i couldn't get the values stored in Picture.any ideas ? thx. ...racking my brain....   
  It could be that Picture[0][0][0] is storing a value that doesnt have a char representation to show when you pass it to cout. I cant remember exactly which values do or dont display something but IIRC the values from 0 to 15 roughly wont show anything. If you have a debugger try stepping through and manually check the memory at Picture[0][0][0].   ;Quote:Original post by greksterIt could be that Picture[0][0][0] is storing a value that doesnt have a char representation to show when you pass it to cout. I cant remember exactly which values do or dont display something but IIRC the values from 0 to 15 roughly wont show anything. If you have a debugger try stepping through and manually check the memory at Picture[0][0][0].THX !!  I tried to debug but failed.  I googled and tried what they said to debug with Dev but I couldn't make it...   ;  If you can't use debugger, you can always display picture[0][0][0] as number instead of char:cout << (int)Picture[0][0][0];You can check the value you get in  ascii table  You will know this way why doesn't it show up.But seriously, you should learn how to debug.   ;Quote:Original post by ShugerIf you can't use debugger, you can always display picture[0][0][0] as number instead of charTHX !  But nothing showed up on my screen.;Quote:Original post by trapezeQuote:Original post by ShugerIf you can't use debugger, you can always display picture[0][0][0] as number instead of charTHX !  But nothing showed up on my screen.Then it sounds likely that the code path where the printing is done is not reached, or that the output stream is never flushed before end of execution. Perhaps try sending a std::flush to cout would help. Otherwise, post the relevant code.   ;  [quoteThen it sounds likely that the code path where the printing is done is not reached, or that the output stream is never flushed before end of execution. Perhaps try sending a std::flush to cout would help. Otherwise, post the relevant code.Thx. you mean adding    using std::flush;    at the beginning ?;  The code is not long. I'm posting it here.-------------------------------------------------#include <iostream>  using namespace std;int main(int argc, char *argv[]){    FILE *file; int BytesPerPixel;    int Size = 256;if  (argc < 3)    {  cout << "usage: program_name input_image.raw output_image.raw[   [BytesPerPixel = 1] [Size = 256]" << endl;   return 0;   }if  (argc < 4)    {  BytesPerPixel = 1;   }    else   {   BytesPerPixel = atoi(argv[3]);if  (argc >= 5)  { Size = atoi(argv[4]); }} unsigned char Imagedata[Size][Size][BytesPerPixel];    if (!(file=fopen(argv[1],"rb"))){  cout << "ERROR" << argv[1] <<endl;  exit(1);}    fread(Imagedata, sizeof(unsigned char), Size*Size*BytesPerPixel, file);    fclose(file);if (!(file=fopen(argv[2],"wb")))    {  cout << "ERROR" << argv[2] << endl;  exit(1);}    fwrite(Imagedata, sizeof(unsigned char), Size*Size*BytesPerPixel, file);    fclose(file);    return 0;}------------------------------------------------------This code just reads pic in and writes the same pic out. The problem is about the values stored in Imagedata...   ;  How do you run your program? The vital thing here is what do you pass to program.I might be wrong but to me it seems like you think that program name is passed as argument to main. If you run your program from command prompt by writing for example:d:/project/program.exe -foo1.raw -foo2.raw  //i don't remember if you have to use '-' haven't used it in ages ;)In this situation your program will receive: argc = 2 and and two strings: foo1.raw and foo2.raw. Program name is NOT passed as argument to main. (i was wrong - read Crypter reply ) edit: fread and FILE are typically for C, in C++ you should use filestreams(ifstream and ofstream).[Edited by - Shuger on September 9, 2007 8:16:09 AM];Quote:Original post by Shugerd:/project/program.exe -foo1.raw -foo2.raw  //i don't remember if you have to use '-' haven't used it in ages ;)In this situation your program will receive: argc = 2 and and two strings: foo1.raw and foo2.raw. Program name is NOT passed as argument to main.Incorrect.Under the command prompt, argv[0]=program name, argv[1]=first parameter, and so on.For example, if this is the command string:d:/project/program.exe -foo1.raw -foo2.rawargc would equal 3, and argv would contain the following:argv[0] = "d:/project/program.exe"argv[1] = "-foo1.raw"argv[2] = "-foo2.raw"Spaces separate the parameters for programs. It is up to the program itself to decipher the meaning of each argument, or use tokens (such as -parm and /parm)@trapeze:You are mixing up the C language with C++. Both of these languages are similar, but should not be treated as the same language. There are alot of things that make these languages different from each other. As such, it is considered bad programming practice to mix these languages as if they were one.I second Shuger's suggestion in using fstream, and take all of your file reading code out, as they are all C, and not C++.Here is a nice tutorial on using fstreamAlso, I recommend against using a 3 dimensional array, if possible. In your current code, it is not necessary.[Edited by - Crypter on September 9, 2007 7:25:26 AM]