If i tried to read above code using following block.
initial
begin
r4 = $fopen("x.log","r");
for (i = 0 ; i < 10; i = i + 1)
begin
t2 = $fscanf(r4,"%h",vr);
$display("%h",vr);
end
i will get follwing output
# 987cba
# 187cba
# 927cba
# 983cba
# 9874ba
# 9874ba
# 9874ba
# 9874ba
# 9874ba
# 9874ba
Eventhogh EOF is reached, it will display the last scanf. How i will
know i have reached while using $fscanf
>Hi
>I am trying to read one file using $fscanf. But eventhough End of file
>is reached, if i tried to read it will displaly the last data which it
>got while fscanf. How i will know EOF is reached.
You need to check the result of fscanf for EOF (end of file) which is
-1 as defined in the spec so:
t2 = $fscanf(r4,"%h",vr);
if (t2 == -1)
$finish;
else ...
should work.
for (i = 0 ; i < 10; i = i + 1)
begin
if ($feof(r4))
$finish; // or break or disable or whatever
else
begin
t2 = $fscanf(r4,"%h",vr);
$display("%h",vr);
end
end
If it's not supported by your simulator directly but SystemVerilog is,
you can call the C library version by creating a DPI import
declaration for it. That's one of the hidden niceties of DPI--you can
call any standard C library function.
-cb
It was added in the 2005 LRM.
> If it's not supported by your simulator directly but SystemVerilog is,
> you can call the C library version by creating a DPI import
> declaration for it. That's one of the hidden niceties of DPI--you can
> call any standard C library function.
To do that, you would have to use the C library for all your file I/
O. There is no standard mechanism to translate between Verilog and C
file descriptors. You cannot just pass a Verilog file descriptor to a
C library function and expect it to work.
Steve,
Thanks. That's good to know. I've used the feature a couple of times,
though not for file I/O, and now I know not to. Fortunately, I don't
anticipate needing to as they've covered the standard file I/O
functions thoroughly enough, I think.
-cb