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

📄 stdinredir2.c

📁 介绍和编写和IO重定向的使用
💻 C
字号:
/* stdinredir2.c * 	shows two more methods for redirecting standard input *	use #define to set one or the other */#include	<stdio.h>#include	<fcntl.h>/* #define	CLOSE_DUP		/* open, close, dup, close *//* #define	USE_DUP2	/* open, dup2, close */main(){	int	fd ;	int	newfd;	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 */	fd = open("data", O_RDONLY);	/* open the disk file	*/#ifdef CLOSE_DUP	close(0);	newfd = dup(fd);		/* copy open fd to 0	*/#else	newfd = dup2(fd,0);		/* close 0, dup fd to 0 */#endif	if ( newfd != 0 ){		fprintf(stderr,"Could not duplicate fd to 0\n");		exit(1);	}	close(fd);			/* close original fd	*/	/* 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 + -