In reply to rockgarden333:
You will have to show a complete example of what you want to do, not just a piece of it.
The following worked for me and it may help you figure out what you want.
module top;
int data,f;
initial begin
f = $fopen("file","r");
while ((data=$fgetc(f)) !=-1) // raw binary
$display("fgetc:%0d %c",data, data);
$fclose(f);
f = $fopen("file","r");
while ($fscanf(f,"%h",data) !=-1) // hex formatted
$display("fscanf: %h",data);
$fclose(f);
end
endmodule
0123 4567
89AB CDEF
Produced the following output
# run -all
# fgetc:48 0
# fgetc:49 1
# fgetc:50 2
# fgetc:51 3
# fgetc:32
# fgetc:52 4
# fgetc:53 5
# fgetc:54 6
# fgetc:55 7
# fgetc:10
#
# fgetc:56 8
# fgetc:57 9
# fgetc:65 A
# fgetc:66 B
# fgetc:32
# fgetc:67 C
# fgetc:68 D
# fgetc:69 E
# fgetc:70 F
# fgetc:10
#
# fscanf: 00000123
# fscanf: 00004567
# fscanf: 000089ab
# fscanf: 0000cdef
# quit -f