Nios II is a 32-bit embedded-processor architecture designed specifically for the Altera family of FPGAs. Having printf() statements in your code sometimes facilitates the debugging effort of your embedded system. However, using printf() statements in an embedded environment without the proper hardware support in your FPGA could be problematic. Specifically, the embedded code could potentially hang/block provided a UART connection is not enabled in your Qsys project and a nios2-terminal is not opened, such that the printf() statement are executed. In systems where a nios2-terminal is not available, including the following lines in your main() code would force non-blocking JTAG UART operations, without causing your code to block.
fcntl(STDOUT_FILENO, F_SETFL, O_NONBLOCK);
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);