Xx_Introduction

  • Character input and output is by more line character conpose of the text flow 
  • Define name common use capital  letter,easy read.
  • The Standard C Library ----->provide I/O model ------>use character flow way.

Ax_Application

  • file copy,charater count,line count,word count

Bx_Method

  • I/O model common use getchar and putchar,interactive use of putchar and printf.

    1 getchar()     //read next character
    2 putcahr() //print next character
    3 printf() //print next(bunch) character
  • File Copy
    • file copy version 1

       1 #include<stdio.h>
      2
      3 int main()
      4 {
      5 int c;
      6
      7 c = getchar();
      8 while(c != EOF){
      9 putchar(c);
      10 c = getchar();
      11 }
      12 }
    • file copy version 2
       1 #include<stdio.h>
      2
      3 int main()
      4 {
      5 int c;
      6
      7 while((c = getchar())!= EOF){
      8 putchar(c);
      9 }
      10 }

      != : unequal to. priority overtop assignment(=)             EOF:end of file

    • Conclusion:computer use bit storage of character and any data type.
    • Assignment can portion of expression.
    • Complex statement simple easy read,but so hard understand.
    • Due to unequal to relational operator(!=) priority not overtop assignment(=),so c expression use bracket.
       1 #include <stdio.h>
      2
      3 int main()
      4 {
      5 int c;
      6
      7 while (c = getchar() != EOF){
      8 printf("%d\n",c);
      9 }
      10 printf("%d - at EOF\n",c);
      11 return 0;
      12 }

      if not use bracket,will priority operation EOF,value by 1,if input end or else print "c - at EOF".

    • Print EOF value programming
      1 #include <stdio.h>
      2
      3 int main()
      4 {
      5 printf("EOF is %d\n",EOF);
      6 return 0;
      7 }

      character constant EOF is in <stdio.h> file definition,value by -1

    • In other system can by definition other value.
  • Charater Count(2019-10-8 update)

    • Character count version 1

       #include <stdio.h>
      
       int main()
      {
      // version 1
      long nc; nc = ;
      while (getchar() != EOF)
      ++nc;
      printf("%ld\n",nc-);
      return ;
      }

      ++(--) is operater, be euivalent to eg(nc = nc + 1);impression add one.

    • ++(--) use a prefix effect in variable before add.in suffix it's first call variable before use progressive increase.
    • Long than int more big,long support 32bit int support 16bit,but different system imparity,long in printf use %ld.
    • Character version 2
       #include <stdio.h>
      int main()
      {
      double nc;
      for (nc = ; getchar() != EOF;++nc)
      ;
      printf("%.0f\n", nc-);
      return ;
      }

      double and float use %f format output.double more than float.

    • For circulation a circulation body must exsit,null statement for alone semicolon(;).
    • Important is circulation in execute programs before must judge test condition whether it meets.
  • Line Count
    • mind:line equal to line break number.
    • Line count program
       #include <stdio.h>
      int main()
      {
      int c,nl; nl = ;
      while ((c = getchar()) != EOF)
      if (c == '\n')
      ++nl;
      printf("%d\n",nl);
      return ;
      }

      ==:mean equal.      'A':mean character constant.corresponding ASCII number.

  • Count blanks,tabs,and newlines.
    • version 1

    •  #include <stdio.h>
      int main()
      {
      int c, nb, nt, nl; nb = ; /* number of blanks */
      nt = ; /* number of tabs */
      nl = ; /* number of newlines */
      while ((c = getchar()) != EOF){
      if ( c == ' ')
      ++nb;
      if ( c == '\t')
      ++nt;
      if ( c == '\n')
      ++nl;
      }
      printf("blanks:%6d\ntabs:%6d\nnewlines:%6d\n", nb, nt, nl);
      return ;
      }

      ....>>>

    • version 2
       #include <stdio.h>
      int main()
      {
      int c, nb, nt, nl; nb = ; /* number of blanks */
      nt = ; /* number of tabs */
      nl = ; /* number of newlines */
      while ((c = getchar()) != EOF)
      if ( c == ' ')
      ++nb;
      else ( c == '\t')
      ++nt;
      else ( c == '\n')
      ++nl; printf("blanks:%6d\ntabs:%6d\nnewlines:%6d\n", nb, nt, nl);
      return ;
      }

      but I not  successful execute.

  • Replace string of blanks with a single blank
    • version 1

       #include <stdio.h>
      #define NONBLANK 'a'
      int main()
      {
      int c, lastc; lastc = NONBLANK;
      while (( c = getchar()) != EOF){
      if (c != ' ')
      putchar(c);
      if (c == ' ')
      if (lastc != ' ')
      putchar(c);
      lastc = c;
      }
      return ;
      }

      one if statement control nonblank output.tow if statement deal with blank.three blank check blank is one or more blank.last print c.

    • version 2

       #include<stdio.h>
      #define NONBLANK 'a'
      int main()
      {
      int c, lastc; lastc = NONBLANK;
      while ((c = getchar()) != EOF ){
      if (c != ' ')
      putchar(c);
      else if (lastc != ' ')
      putchar(c);
      lastc = c;
      }
      return ;
      }

      ok,success!

    • version 3
       #include <stdio.h>
      
       #define NONBLANK 'a'
      int main()
      {
      int c, lastc; lastc = NONBLANK;
      while ((c = getchar()) != EOF){
      if (c != ' ' || lastc != ' ')
      putchar(c);
      lastc = c;
      }
      return ;
      }

      this method use logic simbol (OR) || realize.

    • ok,this aim at blank deal wilth three method.

  • Replace tabs and backspaces with visible characters.
    • Realize

       #include<stdio.h>
      int main()
      {
      int c; while ((c = getchar())!= EOF){
      if (c == '\t')
      printf("\\t");
      if (c == '\b')
      printf("\\b");
      if (c == '\\')
      printf("\\\\");
      if (c != '\b')
      if (c != '\t')
      if (c != '\\')
      putchar(c);
      }
      return ;
      }

      why?//??????????????????????------------------------------program bug.......I brain in the blue screen.so,go to www.baidu.com to find out.

    • Truth  to version 2
       #include<stdio.h>
      int main()
      {
      int c; while ((c = getch())!= EOF){ /*getchar not identify keyboard backspace.*/
      if (c == '\t')
      printf("\\t");
      if (c == '\b')
      printf("\\b");
      if (c == '\\')
      printf("\\\\");
      if (c != '\b')
      if (c != '\t')
      if (c != '\\')
      putchar(c);
      }
      return ;
      }

      getchar not catch backspace so,will getchar replace getch. getch() can catch any print behavior.

    • oh,yes!

    • It can also be used if-else. to version 3
       #include <stdio.h>
      int main()
      {
      int c; while((c = getch())!= EOF)
      if (c == '\t')
      printf("\\t");
      else if (c == '\b')
      printf("\\b");
      else if (c == '\\')
      printf("\\\\");
      else
      putchar(c);
      return ;
      }

      ok.next is a word count.

  • word count
    • count input lines,words and strings number.

       #include <stdio.h>
      #define IN 1
      #define OUT 0 int main()
      {
      int c, nl, nw, nc, state; state = OUT;
      nl = nw = nc = ;
      while ((c = getchar())!= EOF){
      ++nc;
      if (c == '\n')
      ++nl;
      if (c == ' ' || c == '\n' || c == '\t')
      state = OUT;
      else if (state == OUT){
      state = IN;
      ++nw;
      }
      }
      printf("lines:%9d\nword:%9d\nstring:%9d\n",nl,nw,nc);
      return ;
      }

      &&:AND  ||: OR , AND higher priority OR. expression from left to right.         a = b = c = 0   if meanwhile include value and assignment two type,order from right to left.

    • IF statement
       if(expression)
      statement1 /* true */
      else
      statement2 /* false */
      else if (expression){
      statement1 /* true*/
      ...
      }

      true or false.

  • Print input one word per line.
    • last practical program.very basis.very important.

       #include<stdio.h>
      
       #define IN 1
      #define OUT 0 int main()
      {
      int c, state; state = OUT;
      while ((c = getchar()) != EOF){
      if (c == ' ' || c == '\n' || c == '\t'){
      if (state == IN){
      putchar('\n');
      state = OUT;
      }
      } else if (state == OUT){
      state = IN;
      putchar(c);
      } else
      putchar(c);
      }
      return ;
      }

      state is a BOOL value.

Cx_Conclusion

  1. I/O model common use getchar and putchar,interactive use of putchar and printf.
  2. File Copy
  3. Charater Count
  4. Line Count
  5. Count blanks,tabs,and newlines.
  6. Replace string of blanks with a single blank
  7. Replace tabs and backspaces with visible characters.
  8. word count
  9. Print input one word per line.
  10. getchar and putchar printf().and putch()
  11. != and ==\=
  12. ++ / -- 
  13. EOF
  14. LONG and DOUBLE
  15. while and if else
  16. ASCII 'A'
  17. || OR  ; && AND

C lang:character input and output (I/O)的更多相关文章

  1. Python - 3. Input and Output

    from:http://interactivepython.org/courselib/static/pythonds/Introduction/InputandOutput.html Input a ...

  2. 7. Input and Output

    7. Input and Output There are several ways to present the output of a program; data can be printed i ...

  3. [20160704]Addition program that use JOptionPane for input and output

    //Addition program that use JOptionPane for input and output. import javax.swing.JOptionPane; public ...

  4. Python Tutorial 学习(七)--Input and Output

    7. Input and Output Python里面有多种方式展示程序的输出.或是用便于人阅读的方式打印出来,或是存储到文件中以便将来使用.... 本章将对这些方法予以讨论. 两种将其他类型的值转 ...

  5. [Python] Print input and output in table

    Print the input and output in a table using prettyTable. from prettytable import PrettyTable import ...

  6. Input and Output File

    Notes from C++ Primer File State Condition state is used to manage stream state, which indicates if ...

  7. [20171128]rman Input or output Memory Buffers.txt

    [20171128]rman Input or output Memory Buffers.txt --//做一个简单测试rman 的Input or output Memory Buffers. 1 ...

  8. Angular4学习笔记(六)- Input和Output

    概述 Angular中的输入输出是通过注解@Input和@Output来标识,它位于组件控制器的属性上方. 输入输出针对的对象是父子组件. 演示 Input 新建项目connInComponents: ...

  9. Java中的IO流,Input和Output的用法,字节流和字符流的区别

    Java中的IO流:就是内存与设备之间的输入和输出操作就成为IO操作,也就是IO流.内存中的数据持久化到设备上-------->输出(Output).把 硬盘上的数据读取到内存中,这种操作 成为 ...

随机推荐

  1. [开源] .Net 使用 ORM 访问 达梦数据库

    前言 武汉达梦数据库有限公司成立于2000年,为中国电子信息产业集团(CEC)旗下基础软件企业,专业从事数据库管理系统的研发.销售与服务,同时可为用户提供大数据平台架构咨询.数据技术方案规划.产品部署 ...

  2. OA项目之mybatis动态查询

    类似于三个条件,可以全部选择,也可以选择几个条件进行查询 Mapper.xml文件: <resultMap type="Employee" id="selAll&q ...

  3. Day 03 Python 基础

    目录 Pycharm 的使用 设置 快捷键 变量 什么是变量 定义变量 变量名的命名规则 变量名的两种命名方式 注释 快捷键(快速注释) 单行注释 多行注释 注释的作用 Turtle库的使用 Pych ...

  4. 【Web技术】353- CDN 科普

    点击上方"前端自习课"关注,学习起来~ 一.概述 1.1 含义 CDN 的全称是 Content Delivery Network,即内容分发网络.CDN 是构建在网络之上的内容分 ...

  5. Lamada表达式小技巧介绍

    函数式编程 @FunctionalInterface interface Lf{ void dispaly(); } @FunctionalInterface为显示定义函数时编程接口,不符合函数式编程 ...

  6. get请求被浏览器跨域的同源策略请求机制拦截,但是get请求是否请求到了服务器呢

    浏览器会拦截跨域请求,但是只是拦截返回结果,请求还是会被发送到服务器. 请求因为跨域被拦截后,会改成 OPTIONS 请求送达服务器,这样服务器就可以知道有人在请求.

  7. Microsoft store应用商店打不开0x80131500

    开始安装Windows的Linux子系统发现没办法打开应用商店,开始了三个小时的挖贴之路,最终于百度贴吧最底层发现解决办法,同样错误貌似只有两个人.... 首先介绍一下网上普遍的方法↓↓↓ 第一种—— ...

  8. nginx代理grafana

    希望通过Nginx为服务器上的grafana进行代理,实现通过在当前域名后加/grafana在公网进行访问,开始按照百度的方法弄了几个小时都不行,后面仔细看了官方的文档才弄好,Mark一下. Ngin ...

  9. lede install unifi controller

    requirement: sdb3 should be formated as ext4, DO not use f2fs/NTFS/exFAT. debootstrap --arch=amd64 s ...

  10. SpringBoot2基础,进阶,数据库,中间件等系列文章目录分类

    本文源码:GitHub·点这里 || GitEE·点这里 一.文章分类 1.入门基础 SpringBoot2:环境搭建和RestFul风格接口 2.日志管理 SpringBoot2:配置Log4j2, ...