[help] problem on printing message

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
secondtptong
Posts: 3
Joined: Sat Mar 03, 2007 10:16 am

[help] problem on printing message

Post by secondtptong »

Hi all,

I just try to build a simple kernel from the online tutor...

but there is problem to print the string ( it is ok to print a single charater)
below is the code:

Code: Select all

void putch(unsigned char c) // this function is to print a single character
                                        // and work fine
but the following function "puts()" doesnt work when I define the variable as:unsigned char text[]="hello";

if I define it as :
static unsigned char text[]="hello";// work

unsigned char text[]={'h','e','l','l','\0'}; //work

Code: Select all

void puts(void)
{
    int i;

[b]   

  //   unsigned char text[]="hello"; //cannot print the message
    
 //   static unsigned char text[]="hello";// work 
    
   // unsigned char text[]={'h','e','l','l','\0'}; //work
[/b]


    for (i = 0; i < strlen(text); i++)
    {
        putch(text[i]);
    }
}


void main(void)
{


 puts();


}




Thanks in advance
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

puts("Heres what i think");

Post by salil_bhagurkar »

Ok declaring as text[]="hello" worked fine with my putch. You can try the following code:
Instead of putch(text) in puts code try putch(*(text+i)) or
putch(*text);
text++;

And are u passing text to puts? like puts(text). y is puts as puts(void)?
secondtptong
Posts: 3
Joined: Sat Mar 03, 2007 10:16 am

Re: puts("Heres what i think");

Post by secondtptong »

salil_bhagurkar wrote:Ok declaring as text[]="hello" worked fine with my putch. You can try the following code:
Instead of putch(text) in puts code try putch(*(text+i)) or
putch(*text);
text++;

And are u passing text to puts? like puts(text). y is puts as puts(void)?


the original code is :

Code: Select all

void puts(unsigned char *text)
{
    int i;

    for (i = 0; i < strlen(text); i++)
    {
        putch(text[i]);
    }
}


void main()
{
    int i;

    gdt_install();
    idt_install();
    isrs_install();
    irq_install();
    init_video();
    timer_install();
    keyboard_install();

    __asm__ __volatile__ ("sti");

    puts("Hello World!\n");


    for (;;);
}


but it cannt print the "hello world" by " puts("Hello World!\n"); "
unless I use

Code: Select all

    static unsigned char text[]="hello";// work 
    or
    unsigned char text[]={'h','e','l','l','\0'}; //work 
    puts(text);
thx.....
urxae
Member
Member
Posts: 149
Joined: Sun Jul 30, 2006 8:16 am
Location: The Netherlands

Post by urxae »

By "the online tutor", you wouldn't happen to mean "Bran's Kernel Development Tutorial", would you? It's a good tutorial, but it's missing the .rodata section in the linker script. That causes all sorts of trouble with strings...

See: http://www.osdev.org/phpBB2/viewtopic.php?p=89526#89526
secondtptong
Posts: 3
Joined: Sat Mar 03, 2007 10:16 am

Post by secondtptong »

urxae wrote:By "the online tutor", you wouldn't happen to mean "Bran's Kernel Development Tutorial", would you? It's a good tutorial, but it's missing the .rodata section in the linker script. That causes all sorts of trouble with strings...

See: http://www.osdev.org/phpBB2/viewtopic.php?p=89526#89526
exactly right, it is that tutorial..:p


thanks u so much !!!
Post Reply