Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

I cann't use "getchar()"

I add one section code to hello_small_word.c. But it cann't building.

# include "alt_types.h"# include <stdio.h># include <unistd.h># include "system.h"# include "sys/alt_irq.h"# include "altera_avalon_pio_regs.h"# include <string.h>

int main (void) __attribute__ ((weak, alias ("alt_main")));

int alt_main()

{

//alt_u8 c;

int c;

printf("Hello from Nios II!\n");

// while(c = nr_uart_rxchar())

c = getchar();

while (c = &#39;a&#39;)

{

printf("I receive A from my board \n");

}

return 0;

// exit(0);

}

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    what is the error masege that you get?

    and what is the meenning of

    while(c=&#39;a&#39;)

    this will always be true did you ment

    (c==&#39;a&#39;)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    The stdout/stdin/stderr devices are initialized in alt_main by the following code:

    alt_sys_init ();

    /*

    * Redirect stdout etc. to the apropriate devices now that the devices have

    * been initialised. This is only done if the user has requested that the

    * channels been directed away from /dev/null - which is how the channels

    * are configured by default. Making the call to alt_io_redirect conditional

    * allows this function to be excluded from optomised executables when it

    * is unecessary.

    */

    if (strcmp (ALT_STDOUT, "/dev/null") ||

    strcmp (ALT_STDIN, "/dev/null") ||

    strcmp (ALT_STDERR, "/dev/null"))

    {

    alt_io_redirect (ALT_STDOUT, ALT_STDIN, ALT_STDERR);

    }

    /* Call the C++ constructors */

    _do_ctors ();

    In your program, you detele these codes, so it can&#39;t support any stdout/stdin/stderr operation.

    best regards,

    David