# Image file read

**URL:** <https://verificationacademy.com/forums/t/image-file-read/29828>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [August 19, 2014, 1:48pm UTC](https://verificationacademy.com/forums/t/image-file-read/29828 "2014-08-19T13:48:27Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![rockgarden333](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/a4c791/32.png) [@rockgarden333](https://verificationacademy.com/forums/u/rockgarden333)\
**Post date:** [August 21, 2014, 1:12pm UTC](https://verificationacademy.com/forums/t/image-file-read/29828/3 "2014-08-21T13:12:09Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/image-file-read/29828/2):_

Hi Dave,

As $fgetc doesn’t give the input data in correct format i used $fscanf.  
The file actually contains 1440000 bytes (800_600_8). The positive thing is , now it reads all the data  
and goes beyond it. So now i have to check the counter value. Why it doesn’t find the EOF?

I have read the same image using VHDL which uses EOF file checking. So we can conclude the file is not corrupt with EOF.

i changed the code

function void image\_file\_read();  
count = 0;  
while (data\_byte != -1)  
begin  
file\_status = $fscanf(input\_file,“%h”,data\_byte);  
count++;  
$display(“%d %h”,count,data\_byte);

```
		if(count == 1440000)
		    $finish;
        //$fwrite(output_file,read_char);
    end 
    $fclose(input_file);
endfunction : image_file_read

```

---

_[View the full topic](https://verificationacademy.com/forums/t/image-file-read/29828)._
