Stdin,stdout and Stdout_fileno,stdin_fileno--linux__linux

Source: Internet
Author: User
Tags stdin

In Unix system calls, standard input descriptors are used for stdin, standard output is stdout, standard error is expressed in stderr, but in some call functions, reference is made to the Stdin_fileno standard input, the same, standard access Stdout_fileno, Standard error with Stderr_fileno.
The difference between them:
stdin etc is the file * type, which belongs to standard I/O, in <stdio.h>.
Stdin_fileno, etc. are file descriptors, nonnegative integers, generally defined as 0, 1, 2, which belong to I/O without buffer, call system call directly in <unistd.h>.

The following example is applied to Stdout_fifeno and Stdin_fileno: #include <unistd.h> #define SIZE 100
int main (void) {int n; Char Buf[size];
        while (N=read (stdin_fileno,buf,size))   //Read standard input to BUF, returns the number of bytes read.       {                if (N!=write Stdout_fileno , buf,n) BUF write to standard output                         perror ("WRI Te error ");        &NBSP}         if (n<0) perror ("read error");            return 0; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ If you follow the usual method of use: fan@fan:~/arm$ gcc-o App stdout.c  fan@fan:~/arm$./app fdfe fdfe FEFEFEF//input line, immediately output a row, that is, the output is in the original FEFEFEF ============================================== uses redirects to run fan@fan:~/arm$ ./app> data fefe fdadfdf ADFDFEF// The input string is not output to the terminal, but is output to the data file. ========================================================================== fan@fan:~/arm$./app <stdout.c>data fan@fan:~/arm$ //This is the equivalent of copying stdout.c to data ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++= Stdout_fileno and Stdin_fileno are terminals by default, using Ctrl+d to enter file Terminator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.