karlzhao Posted March 22, 2017 Report Share Posted March 22, 2017 Hi Guys, I want to print out some info in the log file as bellow: TEST0001: seed = 12 Out_Str: Hello_test Out_Num: 64 TEST0002: seed = 12345678 Out_Str: Hello_Public_test Out_Num: 1024 I have do this as follows: $fdisplay("TEST%04d: seed = %d Out_str: %s Out_Num: %d", index, seed, out_str, out_num); But I can not got the format which I wanted. Can you tell me how can I do this? Thanks a lot! Quote Link to comment Share on other sites More sharing options...
c4brian Posted March 23, 2017 Report Share Posted March 23, 2017 try this. the '-' means left aligned. choose a size larger than your max, for each field, as in my example. class Packet; int seed[]='{54445,745,11209}; string out_str[]='{"imabigstring","tiny","medium"}; int out_num[]='{88,353,1}; function display (); foreach (out_num) $display("TEST%04d: seed=%-8d Out_str: %-16s Out_Num: %-8d", i, seed, out_str, out_num); endfunction endclass https://www.edaplayground.com/x/2_vR Quote Link to comment Share on other sites More sharing options...
imphil Posted September 16, 2019 Report Share Posted September 16, 2019 Note that negative field width specifiers, as proposed by @c4brian, are non-standard. "The automatic sizing of displayed data can be overridden by inserting a field width between the % character and the letter that indicates the radix. The field width shall be a *non-negative* decimal integer constant." (SV2017, p. 629) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.