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.
- file copy version 1
- Charater Count
原文地址:https://www.cnblogs.com/enomothem/p/11632748.html
时间: 2024-08-01 03:45:34