On Wed, May 6, 2009 at 1:07 PM, abcpqr70 <[email protected]> wrote: > --- In [email protected], Paul Herring <pauljherr...@...> wrote: >> >> On Wed, May 6, 2009 at 10:59 AM, Jos Timanta Tarigan >> <jos_t_tari...@...> wrote: >> > >> > hi, >> > >> > so im currently try to read a binary file and try to represent it in rgb >> > image. i save the >> > file into char[length] and then try to convert it to int to get 0-255 >> > value. is it ok to do it >> > explicitly eg. (int)thisChar ? >> >> In all likelihood, no. >> >> > i got an unexpected value and i wonder if that caused by it. >> >> If by unexpected you mean negative you perhaps need an array of >> >> unsigned char [length]; >> >> instead of >> >> char[length]; >> >> Also check that you're opening the file for binary reads (as opposed >> to text or 'default' which is text on some systems.) >> >> Otherwise you're going to have to explain a bit more.
> well!! I have a similar reaction to your post. > you can't convert a char to int just by typecasting. Um, yes you can. In fact you can do it without typecasting as well. Which is how it normally works. > it will take only the ASCI value of the character and store it in the int > variable. Did you miss the point where the OP was reading the file in Binary, not Text (of course, assuming you know that there are other formats for text other than ASCII.) > to convert to int you need to use the function:- atoi() > int atoi ( const char * str ); How does that work with a binary stream? You know, where (say) an int is stored in 4 characters, rather than the more readable 1-8 characters. > and i hope this ASCI value is the unexpected value you were talking about I wasn't talking about anything - perhaps you should have replied to the OP's original question rather than my answer to it? > hope it helped you! Not in the slightest. I'm turning into Victor, aren't I? -- PJH http://shabbleland.myminicity.com/com http://www.chavgangs.com/register.php?referer=9375
