Vishwasu Deshpande
Vishwasu Deshpande

Reputation: 59

Read Variable length string in a file using SystemVerilog

Suppose I have variable length string as below:

Write <Address> <Data0> <Data1> <Data2>
Read <Address>
Write <Address> <Data0>
Write <Address> <Data0> <Data1> <Data2> <Data3>

How do I read in SystemVerilog or Verilog using file operations. I know to read when there is fixed length of text

integer file    = $fopen(file_name,"r");
code = $fgets(line, file);
code = $sscanf(line, "%s %h %h %h", txn_type, Address, Data[i]);

Upvotes: 0

Views: 1533

Answers (1)

dave_59
dave_59

Reputation: 42748

You can use $sscanf when the number of fields is not fixed, as long as you supply the maximum possible number of fields. The return value placed in code indicates the actual number of arguments scanned. So just create a dummy list of arguments and copy the ones provided by the line

Upvotes: 2

Related Questions