printf() problem

Brad Brown bradb at ai.toronto.edu
Thu Apr 27 10:16:13 AEST 1989


In article <11657 at hodge.UUCP> jdm at hodge.UUCP (jdm) writes:
>
>    I have a file with binary data.  I want to read four consecutive
>    bytes from the file and display them with printf().  The data
>    in in the file in hex is:
>
>        92 AB 4E 33
>
>    I fopen() the file in binary mode and used the following line
>    of code to read and print out the data:
>
>        printf("%x %x %x %x\n", getc(fp), getc(fp), getc(fp), getc(fp));
>
>    Although the order of the data in the file is:

C makes no guarantees about the order in which arguments are evaluated --
K&R says this and several other places do to.  That's why you CAN'T 
have functions with interdependant side effects in the argument list
of a function call -- you can't say which one will execute first.

Unfortunately your solution 

>        a = getc(fp);
>        b = getc(fp);
>        c = getc(fp);
>        d = getc(fp);
>
>        printf("%x %x %x %x\n", a, b, c, d);

is (an) appropriate one because you have to get consecutive reads out of
the argument list.

					(-:  Brad Brown  :-)
					bradb at ai.toronto.edu



More information about the Comp.lang.c mailing list