• 程序运行


    1 理解test.c, 说出程序功能

    #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 );
    }
    
    

    2 编译运行程序,提交运行截图

    首先先新建一个文件,里面输入我的学号,然后运行程序。我输入数字,程序会打印我输入的数字。输入三遍后程序会打印我刚刚新建文件里的内容

  • 相关阅读:
    POJ 2065 高斯消元求解问题
    HDU1045-Fire Net
    HDU1863-畅通工程
    POJ2524-Ubiquitous Religions
    POJ1064-Cable master
    POJ2456-Aggressive cows
    HDU1272-小希迷宫
    POJ1611-The Suspects
    HDU4496-D-City
    HDU1232-畅通工程
  • 原文地址:https://www.cnblogs.com/ffffatal/p/15682631.html
Copyright © 2020-2023  润新知