C
C#7mo ago
Ewan

✅ How do i move to the next line on a text file and output both lines?

The first image prints the same line twice onto a text file which is expected For the second image, the console.readline() should move to the next line and print that out after the first but it doesnt, it doesnt print anything help please!
No description
No description
14 Replies
Sossenbinder
Sossenbinder7mo ago
You mean the second line should print what is being read through ReadLine()?
Ewan
Ewan7mo ago
yeah so on the first image, it outputs the first line on the text file twice i want it to, on the second image, output the first line of the text file and then the next line
Sossenbinder
Sossenbinder7mo ago
In that case, Console.ReadLine() returns the line it read, so you need to actually assign it to a string you want to print
Ewan
Ewan7mo ago
but its not doing that on the second image ;-; how?
Sossenbinder
Sossenbinder7mo ago
var readString = Console.ReadLine(); Console.WriteLine(readString); You can also reassign one of the variables you print But from your screenshot I can't tell which is supposed to be what
Ewan
Ewan7mo ago
my code is way too long and complexed, ill try this out
SinFluxx
SinFluxx7mo ago
you don't mean you're trying to read from the same file you're writing to do you?
Ewan
Ewan7mo ago
its from the same file the file has more than one line i want to output the lines seperately i dont understand this how do i assign it to a string i want to read
SinFluxx
SinFluxx7mo ago
trying to read from and write to the same file simultaneously will probably be painful - if you can do all your writing first and the read it (or vice versa) that'll be a lot easier, depends what you're trying to achieve really
Ewan
Ewan7mo ago
is the string the file contnets oh wait no, im reading from one file and then writing to another
SinFluxx
SinFluxx7mo ago
Console.ReadLine() reads what the user types into the Console, not from a file
Ewan
Ewan7mo ago
but i need to read seperate lines in one file to write the seperate lines on the other file
SinFluxx
SinFluxx7mo ago
is there a reason you need to specifically read one line, write one line before moving on?
Ewan
Ewan7mo ago
in the overall code im trying to make, the file has seperate lines with number values and other data. im trying to get these values and print it onto another file order from highest to lowest so i need them seperately as each line is different values an all nighter trying to do something as simple as just reading and outputting the next line it is!