• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. How to dynamic change the number to format ( Writes formatted...

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 143
  • Views 14347
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to dynamic change the number to format ( Writes formatted output to a port.) ?

Charley Chen
Charley Chen over 7 years ago

Hi All,

How to dynamic change the number  10 ==> 15 ?  ( Writes formatted output to a port.)

I want 10s is not fixed , it dependents on a interger variable (e.g. a = 10 , a= 15)

fprintf( op "%10s\n" line)  => fprintf( op "%15s\n" line)

Thank you,

Charley

  • Cancel
  • RK56
    RK56 over 7 years ago

    How about this way? Create a string with the required format and then evaluate the string. I remember Perl having a way of doing this directly but not in skill. Others please correct me.

    fmtCmd = sprintf(nil, "printf(\"%%%ds\n\" \"line\")" formatInt)
    evalstring(fmtCmd)

    -Ramakrishnan

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Charley Chen
    Charley Chen over 7 years ago in reply to RK56

    Hi Ramakrishnan ,

    Yes, It works. Thank you.

    Charley

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to Charley Chen

    Using evalstring (and hence run-time evaluation) is a really bad way of doing this - it's unnecessary. You can take the same idea but do it much more cleanly and without needing to revert to run-time evaluation:

    sprintf(formatStr "%%%ds\n" fieldWidth)
    fprintf(op formatStr line)

    Unfortunately SKILL doesn't support the "%*s" construct that the C printf does, which would have made this even easier.

    Regards,

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Charley Chen
    Charley Chen over 7 years ago in reply to Andrew Beckett

    Hi Andrew ,

    It's OK for one field.

    If i have 4 field needs to op , How to write ?

    Thank you,

    Charley

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RK56
    RK56 over 7 years ago in reply to Andrew Beckett

    Agreed. This is much netter

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Charley Chen
    Charley Chen over 7 years ago in reply to RK56

    Hi Andrew,

    I got it. It works. Thank you very much

    sprintf(formatStr "%%%ds  %%%ds  %%%ds  %%%ds\n" fieldWidth  fieldWidth  fieldWidth  fieldWidth)
    fprintf(op formatStr line1 line2 line3 line4)

    Charley

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information