• C语言学习021:管道


    将第一个程序的输出流作为第二个程序的输入流

    ls /etc/   ---------显示etc下的所有文件及目录
    grep rc   -----------输出包含rac的内容
    |      -------连接管道
    

    一个计算平均工资的例子,通过管道将两个小程序连接起来,一个是将工资统计起来并输出总数和个数,另一个程序接收总金额和个数,计算平均值后输出

    #include <stdio.h>
    
    int main()
    {
        int count=0;
        int sum=0;
        int i;
        int flag=1;
        while(flag){
          scanf("%d",&i);
          if(0==i) break;
          count++;
          sum+=i;
        }
        printf("%d,%d",sum,count);
        return 0;
    }
    
    #include <stdio.h>
    
    int main()
    {
        int sum;
        int count;
        scanf("%d,%d",&sum,&count);
        int avg=sum/count;
        printf("avg=%d
    ",avg);
        return 0;
    }
    

    {300*}

  • 相关阅读:
    ajax全套
    url设计规范
    内置下划线方法
    rest_framework视图
    rest_framework
    数据库设置
    HDU 6231
    HDU 6242
    CodeForces 546D
    CodeForces 940E
  • 原文地址:https://www.cnblogs.com/liunlls/p/c-conduit.html
Copyright © 2020-2023  润新知