编程语言
首页 > 编程语言> > 程序运行

程序运行

作者:互联网

1 理解test.c, 说出程序功能
2 编译运行程序,提交运行截图

#include  <stdio.h>
#include  <stdlib.h>
#include  <fcntl.h>

main()
{
	int	fd ;
	int	newfd;
	char	line[100];

	fgets( line, 100, stdin ); printf("%s", line );
	fgets( line, 100, stdin ); printf("%s", line );
	fgets( line, 100, stdin ); printf("%s", line );

	fd = open("data", O_RDONLY);	

	newfd = dup2(fd,0);	
	
	if ( newfd != 0 ){
		fprintf(stderr,"Could not duplicate fd to 0\n");
		exit(1);
	}
	close(fd);			

	fgets( line, 100, stdin ); printf("%s", line );
	fgets( line, 100, stdin ); printf("%s", line );
	fgets( line, 100, stdin ); printf("%s", line );
}

标签:程序运行,stdin,fd,printf,fgets,line,100
来源: https://www.cnblogs.com/mjy0911/p/15682639.html