Linux_c DUP ()

Source: Internet
Author: User
Tags stdin

1 /*2 * stdinredir2.c3 * shows, methods for redirecting , standard input4 * Use #define to set one or the other5  */6#include <stdio.h>7#include <fcntl.h>8 /*#define Close_dup/*open, close, DUP, close*/9 /*#define USE_DUP2/*opne, dup2, close*/Ten intMainvoid) { One   intFD, NEWFD; A   Charline[ -]; -   //Read and Print lines -Fgets (Line, -, stdin); theprintf"Line :%s", line); -    -Fd=open ("/home/wiz/wizcode/psh1.c", o_rdonly);/*Open the disk file*/ -  + #ifdef close_dup -Close0); +Newfd=dup (FD);/*copy open fd to 0*/ A   #else atNewfd=dup2 (FD,0);/*close 0, DUP fd to 0*/ -   #endif -   if(newfd!=0){ -fprintf (stderr,"Could not duplicate fd to 0\n"); -Exit1); -   } in Close (FD); -Fgets (Line, -, stdin); printf"%s", line); toFgets (Line, -, stdin); printf"%s", line); +Fgets (Line, -, stdin); printf"%s", line); -   return 0; the}

Linux_c DUP ()

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.