• 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. Reading String from txt file

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 143
  • Views 20924
  • 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

Reading String from txt file

frasheed
frasheed over 11 years ago

Hello All,

I am writing a short code to read Strings from a file.

Example of file that I want to read.

SAMPLE DATA

Name "Technology" "Version" "revision"

started "15july" "30july"

label "New" "Old"

and the code is

f = infile(my.txt)

while( str = lineread(f)
        case( car(str)
            ( Name               
                  Name = cdr(str)
             )                 
            );; end case

);; end while

Now after reading the values store in Name variable is ( "Technology" "Version" "revision"), and when I check the type for variable "Name" its showing me "list" but when I access any element using nth(0 Name) then its giving me ("Technology"), which is neither symbol nor string , I want it to be string without the paranthesis.

Any Good way to do that, I tried  pcExprToString command but its not giving me the desired output. 

Thanks

 

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 11 years ago

    No it doesn't. nth(0 Name) will return "Technology". Or you could use car(Name):

    > Name
    ("Technology" "Version" "revision")
    > car(Name)
    "Technology"
    > cadr(Name)
    "Version"
    > nth(1 Name)
    "Version"
    > nth(2 Name)
    "revision"
    > nth(0 Name)
    "Technology"

    Presumably what you've done doesn't match what you've posted (after all your infile is missing quotes around the filename, so I'm assuming the code wasn't necessarily cut and pasted into the post).

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • frasheed
    frasheed over 11 years ago

     Hi Andrew, 

    Yeah I edited my code here so I forgot the quotes for the infile :). But I don't know how but I just re wrote the data in my.txt file and Its reading like you mentioned in ur reply. Thanks

    Anyway to read the data directly as a string ? my.txt data file is not fixed I will always change the data , Otherwise I would have used fscanf(%s), What you would suggest me ?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 11 years ago

    You could use gets() to read one line at a time, and then use the pcre.* functions to pull out various parts of the text - without knowing your precise requirements I can't really give you a detailed answer.

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • frasheed
    frasheed over 11 years ago

     Thanks for the quick reply.Actually It was my Mistake I was checking the type for the whole variable which is a string , if I check the type of nth(0 Name) then its String.

     

    • 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