I am trying to open a file and read it’s content in an array. The file handler is not getting populated throwing an error “file can not be opened. No such file or directory”. The file that I am trying to open is in the same directory. Could you please suggest anything to overcome this file read issue?
Here is the code snippet:
virtual task main_phase(uvm_phase phase);
integer i, file_handle;
You should try to write to a file and see if it gets created in the same directory that you are trying to read from. Also $fopen returns 0 if it is not able to open the file, not null. The ‘value’ of null is not defined.
try opening file with $fopenr(“File_name”).
e.g
integer file1;
bit return_val;
bit [7:0]mem[64:0];
initial
begin
file1= $fopenr(“pattern.txt”);
for( int i=0;i < 64; i++)
begin
return_val= $fread(mem[i] ,file1);
$display(“Data read from file is mem[%d] = %h”,i,mem[i]);
end
end
Be sure, pattern.txt is present in same folder.