Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!ephemeral.ai.toronto.edu!bradb From: bradb@ai.toronto.edu (Brad Brown) Newsgroups: comp.lang.c Subject: Re: printf() problem Keywords: C printf Message-ID: <89Apr26.201617edt.10785@ephemeral.ai.toronto.edu> Date: 27 Apr 89 00:16:13 GMT References: <11657@hodge.UUCP> Organization: Department of Computer Science, University of Toronto Lines: 34 In article <11657@hodge.UUCP> jdm@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@ai.toronto.edu