module file_read()
parameter EOF = -1;
integer file_handle,error,indx;
reg signed [15:0] wide_char;
reg [7:0] mem[0:255];
reg [639:0] err_str;
initial begin
indx=0;
file_handle = $fopen(“text.txt”,”r”);
error = $ferror(file_handle,err_str);
if (error==0) begin
wide_char = 16’h0000;
while (wide_char!=EOF) begin
wide_char = $fgetc(file_handle);
mem[indx] = wide_char[7:0];
$write(“%c”,mem[indx]);
indx = indx + 1;
end
end
else $display(“Can’t open file…”);
$fclose(file_handle);
end
endmodule