How can I read a string array from file in verilog?
There are no built-in SystemVerilog routines to do this like there are for integral memories.
You will have to read the file in a loop using $fgets or $fscanf.
In reply to dave_59:
but $fgets and $fscanf commands read the values till new line.
and in my case I have some values in the line and I want them to load in the array correspondingly.
In reply to Devory:
$fscanf reads data matching a format specifier, and anything else is left unread. Note that the %s format specifier does not read whitespace. So if your strings are delimited by something else (like quotes), that becomes a much more difficult problem.
In reply to dave_59:
could I continue the next value in the same line after using $fscanf command
or the $fscand defined to go down line?
In reply to Devory:
If your file is
A AB ABC
B BC
C CD CDE FGR
E
F
G
Then this code
module top;
string s[$];
int f;
initial begin
string w;
f = $fopen("strings.txt","r");
while ($fscanf(f,"%s",w) != -1) s.push_back(w);
$display("%p",s);
end
endmodule
should display
'{“A”, “AB”, “ABC”, “B”, “BC”, “C”, “CD”, “CDE”, “FGR”, “E”, “F”, “G”}