Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to write to stdout in C?

Tags:

c

unix

stdout

Does a program that writes to "stdout" write to a file? the screen? I don't understand what it means to write to stdout.

like image 981
Acroyear Avatar asked May 07 '13 23:05

Acroyear


People also ask

What does it mean to write to standard output?

Stdout, also known as standard output, is the default file descriptor where a process can write output. In Unix-like operating systems, such as Linux, macOS X, and BSD, stdout is defined by the POSIX standard. Its default file descriptor number is 1. In the terminal, standard output defaults to the user's screen.

What is stdin and stdout in C?

In computer programming, standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), standard output (stdout) and standard error (stderr).

How do I print a string from stdout?

In C, to print to STDOUT, you may do this: printf("%sn", your_str); For example, $ cat t.c #include <stdio.


1 Answers

That means that you are printing output on the main output device for the session... whatever that may be. The user's console, a tty session, a file or who knows what. What that device may be varies depending on how the program is being run and from where.

The following command will write to the standard output device (stdout)...

printf( "hello world\n" ); 

Which is just another way, in essence, of doing this...

fprintf( stdout, "hello world\n" ); 

In which case stdout is a pointer to a FILE stream that represents the default output device for the application. You could also use

fprintf( stderr, "that didn't go well\n" ); 

in which case you would be sending the output to the standard error output device for the application which may, or may not, be the same as stdout -- as with stdout, stderr is a pointer to a FILE stream representing the default output device for error messages.

like image 130
K Scott Piel Avatar answered Oct 12 '22 23:10

K Scott Piel