Problem with printing

Hello, i want to make OS, and i have Kernel,Bootloader, and i have problems with this code:
// Print single char
void printch(char c){
string memory = (string)0xb8000;
memory[((CursorX * sw + CursorY))*sd] = c;
CursorY++;
updateCursor();
}

// Print string
int str_size = 0;
void print(const char* str){
while(str_size <= sizeof(str_size)){
printch(str[str_size]);
str_size++;
}
}

in Main functioin is : print("something");
but in output is only: somet
closed account (D80DSL3A)
output is only: somet

That makes sense. The number of while loop iterations = sizeof(str_size) + 1.
while(str_size <= sizeof(str_size))
If sizeof(int) = 4 on your system the 5 character output is explained.
You want to output all of the characters in the string.
consider instead:
while(str_size < strlen(str))
though you need to #include <cstring> for the strlen function.

Another way is to loop until the null terminator is found at the end of the string:
1
2
3
4
while(str[str_size] != '\0'){
printch(str[str_size]);
str_size++;
}
Last edited on
Topic archived. No new replies allowed.