Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
