Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

6.7.1. Standard Input, Standard Output and Standard Error

Using standard input (stdin), standard output (stdout), and standard error (stderr) is the easiest way to implement simple console I/O. The HAL manages stdin, stdout, and stderr behind the scenes, which allows you to send and receive characters through these channels without explicitly managing file descriptors. For example, the HAL directs the output of printf() to standard out, and perror() to standard error. You associate each channel to a specific hardware device by manipulating BSP settings.
Note: This program sends characters to whatever device is associated with stdout when the program is compiled.

Example 6–3. Hello World

#include <stdio.h>
int main ()
{
printf ("Hello world!");
return 0;
}

When using the UNIX-style API, you can use the file descriptors stdin, stdout, and stderr, defined in unistd.h, to access, respectively, the standard in, standard out, and standard error character I/O streams. unistd.h is installed with the Nios II EDS as part of the newlib C library package.