Help! strings don't work
Posted: Sun Jun 05, 2011 2:24 am
Hello, I'm new to OSDev.org, I've followed the Bare Bone guide of C kernel and it works...
But there is something weird when I use strings.
If i do
it works
But if I do
it doesn't.
I've noticed that if I do
the condition is satisfied...
It seems that char* y is different to char x[]
but in normal programming it works both ways.
PS: This is the code of kprint, putchar and cls
Thanks in advance
But there is something weird when I use strings.
If i do
Code: Select all
cls();
char x[] = "Welcome to My OS!\n";
kprint(x);
But if I do
Code: Select all
cls();
char* y = "Welcome to My OS!\n";
kprint(y);
I've noticed that if I do
Code: Select all
if(*y == 0) putchar('?');
It seems that char* y is different to char x[]
but in normal programming it works both ways.
PS: This is the code of kprint, putchar and cls
Code: Select all
void putchar(char c)
{
if (c == '\n')
{
LF(); //NewLine
return;
}
int addr = ((ypos * COLUMNS) + xpos) * 2;
video[addr] = c & 0xFF;
video[addr + 1] = 0x07;
xpos++;
if (xpos >= COLUMNS) LF();
}
void kprint(const char* str)
{
//while(*msg) putchar(*msg++);
int i = 0;
while(str[i])
{
putchar(str[i++]);
}
}
void cls (void)
{
int i;
video = (unsigned char *) VIDEO;
for (i = 0; i < COLUMNS * LINES * 2; i++)
*(video + i) = 0;
xpos = 0;
ypos = 0;
}