Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Read a String from a File Create a new text file in your prac _ 0 9 directory called name.txt . Type only your own
Read a String from a File
Create a new text file in your prac directory called name.txt
Type only your own name in the file.
Write a program in question that reads this name.txt file and greets you, example:
Greetings Lindsay!
Note that since we want the entire contents of the file in one string, we don't need any kind of loop, we can just read
the file, like:
infile opennametxtr
text infile. read
Did it work?
If you got something like
Greetings Lindsay
Then what happened is the text variable includes the new line character In in your file.
You can solve this problem in two ways.
Edit the file so there's no new line
Strip the new line character any whitespace from the ends of the line from text with:
text infile.read
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started