ntubski |
11-02-2007 12:54 PM |
Quote:
Originally Posted by brazilnut
(Post 2945774)
OK, i've changed the following line in the 'binreader()' function and now it looks OK, but maybe someone has some other ways...
Code:
printf("%d: %d : %c \n", i++, (unsigned int)((unsigned char)ch), ch);
When I tried doing this with the 'while ((ch = getc(fi))!= EOF)' line, it tripped saying unable to reinterpret EOF, therefore, how to read in unsigned char's?
|
getc() returns an int. EOF is usually define as -1, when you cast the unsigned char 255 into signed char (which is what happens you assign to ch) you will also get -1, so the code won't work as expected in all circumstances (see 2's complement). Basically, declare ch an int should fix things.
Also testing the return value of rand() against EOF doesn't make much sense, nor does taking the absolute value of it since it returns a positive number anyway. You never return a value from gen_random_file() even though you declared it to return an int.
|