⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stdinredir1.c

📁 unix linux 编程实践源代码
💻 C
字号:
/* stdinredir1.c *	purpose: show how to redirect standard input by replacing file  *		 descriptor 0 with a connection to a file. *	 action: reads three lines from standard input, then *		 closes fd 0, opens a disk file, then reads in *		 three more lines from standard input */#include	<stdio.h>#include	<fcntl.h>main(){	int	fd ;	char	line[100];	/* read and print three lines */	fgets( line, 100, stdin ); printf("%s", line );	fgets( line, 100, stdin ); printf("%s", line );	fgets( line, 100, stdin ); printf("%s", line );	/* redirect input */	close(0);	fd = open("/etc/passwd", O_RDONLY);	if ( fd != 0 ){		fprintf(stderr,"Could not open data as fd 0\n");		exit(1);	}	/* read and print three lines */	fgets( line, 100, stdin ); printf("%s", line );	fgets( line, 100, stdin ); printf("%s", line );	fgets( line, 100, stdin ); printf("%s", line );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -