• 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. Write String to a File question

Stats

  • Locked Locked
  • Replies 10
  • Subscribers 144
  • Views 17759
  • 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

Write String to a File question

netbug
netbug over 9 years ago

Dear all,

This is a simple question.

I am using a form to collect data entered by the user. I would like to store this data into a text file, separating each field into different lines in the text file.

I have come up with a solution that is far away from being the best. I have stored all the information into a string and then I've parsed into a list. After that each element of list is written into the file in separate lines.

Please find my code below. In this case I am already passing the list and not the string.

Thanks in advance,

Pedro

procedure(WriteToFile(myPath myList)
let((myPort FileExists txtStr delimiter)
FileExists=isFileName(myPath) ; Test if the file exists

; Check if config file exists
if((FileExists==t) then
printf("File Exists !")
else
myPort=outfile( myPath ) ; open file for write
for( i 0 length(myList)-1 ; loop through the list
str=nth(i myList)
fprintf(myPort "%s\n" str) ; write string to file
)
close( myPort ) ; close file
printf("File Created !")
); end if
); End let
); End procedure

 

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 9 years ago

    Unknown said:
    Usually with lists it is better to use foreach() than for(), but that is because the code is simpler. The performance only starts to really matter when your lists are 100 elements long.

    Why use an approach that is more complex and requires more code and when you suddenly find yourself dealing with larger lists than you anticipate will get slow very quickly? Yes, for short lists it tends to be insignificant, but then it depends on how many times you are calling the piece of code that is doing this. 

    Much better to get into a good habit in the first place rather than writing code that is stylistically worse and also liable to be inefficient.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • rish87
    rish87 over 6 years ago in reply to Andrew Beckett

    Hi Andrew,

    I would like to open a file in append mode and then write some variables value to the starting of the file(there are some texts exists in the starting of the file).

    Is there any function to write the file from starting? I don't want  to read the file and store it somewhere and again rewrite the file.

    Thank you

    Harish 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • mbracht
    mbracht over 6 years ago in reply to rish87

    Hi Harish,

    I don't think this is possible - and it is not a limitation of SKILL but of the Unix filesystem. So you need to recreate the file...

    Max

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • mbracht
    mbracht over 6 years ago in reply to rish87

    Hi Harish,

    I don't think this is possible - and it is not a limitation of SKILL but of the Unix filesystem. So you need to recreate the file...

    Max

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
No Data

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