The line does not end with the character "\n"
Posted: Mon Dec 16, 2019 12:00 am
When I use printf, and if I want to end the line with "\ n", then it does not end and some character appears


The Place to Start for Operating System Developers
https://forum.osdev.org/

I took the printf code from here: https://wiki.osdev.org/Meaty_Skeleton#l ... 2Fprintf.cMichaelPetch wrote:Looks like you wrote or borrow someone's printf code that writes directly to the screen. If that is the case it appears the printf you are using doesn't translate \n (and likely \r and other special characters. The values for their characters are being literally written to the screen and you see the ASCII representation. printf and the underlying code/functions for screen output would have to be amended to handle such cases.
I do not seeiansjack wrote:Can you see anywhere in that code where "\n" is handled?
I think *you* know how to handle it, you just don't know how to write code that will tell the computer how to handle it. Actually, I suspect you know how to tell the computer how to handle it, but that you don't know that you know.Gebet94 wrote:
I do not see. But how to handle \n, I don't know
The cursor moves to a new line?.. How else to say, I don't knowlinguofreak wrote:Question 1: In English (not C), what needs to happen when there is a newline in a string?
Simply put, you need to keep track of your cursor's location. You can have two variables, let's say cursor_row and cursor_col which contain the current location of the cursor. Let them be initialized with 0.Gebet94 wrote:The cursor moves to a new line?.. How else to say, I don't knowlinguofreak wrote:Question 1: In English (not C), what needs to happen when there is a newline in a string?
Thank you, and thank you all too. I will consider all my mistakesiocoder wrote:Question 1: In English (not C), what needs to happen when there is a newline in a string?
The cursor moves to a new line?.. How else to say, I don't know
Simply put, you need to keep track of your cursor's location. You can have two variables, let's say cursor_row and cursor_col which contain the current location of the cursor. Let them be initialized with 0.
Whenever you print a character to screen, you read cursor_row and cursor_col and write the character (and the associated attributes) to the location specified by cursor_row and cursor_col, then update cursor_row and cursor_col to move the cursor to the next cell.
If you want to print a newline ('\n'), then the code would simply update cursor_row and cursor_col to move the cursor to next line.
Now since cursor_row and cursor_col refer to the first cell of a new line, the next character to be printed will be put at this specified location (the beginning of the new line), then the code will update cursor_row and cursor_col as usual.
Does this make sense? I think the main issue here is copying the code without having a vision for the design of your software program. You need to design the thing from scratch and then ask yourself how to implement it.
Gebet94 wrote:The cursor moves to a new line?..linguofreak wrote:Question 1: In English (not C), what needs to happen when there is a newline in a string?
Code: Select all
We'll get
a stairstep effect
like thisDon't overthink it. I'm generally looking for fairly simple answers here.How else to say, I don't know