C lang:character input and output

Posted enomothem

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C lang:character input and output相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Character.digit()的意义

字符串验证

Sort an input string using an arbitrary alphabet

65 不变模式2

如何使程序可以获得用户输入的特殊字符的值

[GraphQL] Create an Input Object Type for Complex Mutations