码迷,mamicode.com
首页 > 其他好文 > 详细

C lang:character input and output

时间:2019-10-07 23:18:06      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:over   data   cti   std   get   ram   while   stand   top   

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

C lang:character input and output

标签:over   data   cti   std   get   ram   while   stand   top   

原文地址:https://www.cnblogs.com/enomothem/p/11632748.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!