• 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

    I disagree. The code is using a for loop to iterate over a list, and then nth() to access each element. If the list isn't too long, that's OK, but it's a bad paradigm to start using - it will lead you into trouble. The reason being that lists are sequential, so doing this is order of N^2 (each time you use nth it has to start counting from the beginning of the linked list). It would be better to use foreach() over the list, or you could use pprint() to write the list out in one go - and then lineread to read it back in again. 

    You might also want to look at http://community.cadence.com/cadence_technology_forums/f/48/p/13412/20801#20801which gives an example of saving info from a form and loading it again later.

    Regards,

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 9 years ago

    I disagree. The code is using a for loop to iterate over a list, and then nth() to access each element. If the list isn't too long, that's OK, but it's a bad paradigm to start using - it will lead you into trouble. The reason being that lists are sequential, so doing this is order of N^2 (each time you use nth it has to start counting from the beginning of the linked list). It would be better to use foreach() over the list, or you could use pprint() to write the list out in one go - and then lineread to read it back in again. 

    You might also want to look at http://community.cadence.com/cadence_technology_forums/f/48/p/13412/20801#20801which gives an example of saving info from a form and loading it again later.

    Regards,

    Andrew

    • Cancel
    • Vote Up 0 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