EOF? ?? ?? - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

EOF? ?? ??

Description:

21 . 21-1 , , ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 19
Provided by: yoo75
Category:
Tags: eof

less

Transcript and Presenter's Notes

Title: EOF? ?? ??


1
21?. ??? ??? ?? ??
2
21-1 ???? ???? ??
  • ????? ??
  • ??, ??, ?? ????
  • ???? ?? ??
  • ???? ???? ?? ?? ??? ??

?? 21-1
3
21-1 ???? ???? ??
  • ?? ???? ???
  • ???? ?? ? ???? ?? ? ??
  • ???? ???? ? ???? ?

?? ???? ?? ??? ??
stdin ?? ?? ??? ???
stdout ?? ?? ??? ???
stderr ?? ?? ??? ???
? 21-1
4
21-2 ?? ?? ???? ??
  • ?? ?? ??

include ltstdio.hgt Int putchar(int c) Int fputc(int c, FILE stream)
??? ???? ?? EOF ??
  • ?? ?? ??

include ltstdio.hgt Int getchar(void) Int fgetc(FILE stream)
??? ????? ??? ?? ???? ?? EOF ??
5
21-2 ?? ?? ???? ??
  • EOF? ?? ??
  • fgetc, getchar ??? ??? ?? ???? ?? ??
  • End-Of-File? ????, ??? ?? ???? ?? ??
  • (-1? ?? ???)
  • ??? ?? Ctrl-Z? ??? EOF? ??
  • ?? Ctrl_Z.c ??
  • ?? ?? ? ??? ??? ???
  • ??? ?? ??? ??? ?????? ?? ??? ??

6
21-2 ?? ?? ???? ??
/ Ctrl_Z.c/ include ltstdio.hgt int
main() char ch0 while(ch !
EOF) chgetchar()
putchar(ch) printf("program ??
\n") return 0
/ char_IO.c/ include ltstdio.hgt int
main() char ch0 while(ch !
'q') chgetchar()
putchar(ch) return 0
7
21-3 ??? ?? ???? ??
  • ??? ?? ??

include ltstdio.hgt Int puts(const char s) Int fputs(const char s, FILE stream)
??? ???? ?? EOF ??
  • ??? ?? ??

include ltstdio.hgt char gets(char s) char fgets(char s, int n, FILE stream)
??? ????? ??? ?? ???? ?? NULL ??? ??
8
21-3 ??? ?? ???? ??
/ puts_fputs.c/ include ltstdio.hgt int
main() fputs("fputs ??? ?? ??, ",
stdout) fputs("I Love Linux ", stdout)
fputs("\n", stdout) // ? ? ?? ?? ???.
puts("puts ??? ?? ??,") puts("I Love Linux
") return 0
/ fputs.c / include ltstdio.hgt int main()
char str10 fputs("???? ?? ???
", stdout) fgets(str, sizeof(str),
stdin) fputs("??? ??? ", stdout)
fputs(str, stdout) return 0
9
21-4 ?? ????? ??(Buffer)
  • ??? ??? ???? ??? ??
  • ??? ?? ???? ??? ???.
  • ?? ??? ????.
  • ??? ???, ??? ??...

?? 21-2
10
21-4 ?? ????? ??(Buffer)
  • ??? ??? ??? ?? fflush ??
  • fflush ??? ???
  • ?? fflush.c ??

include ltstdio.hgt int fflush(FILE stream)
?? ? 0, ?? ? EOF ??
?? 21-3
11
21-4 ?? ????? ??(Buffer)
/ fflush.c / include ltstdio.hgt int
main(void) char perID7 // 6null??7
char name10 fputs("???? ? 6 ??? ?????
", stdout) fgets(perID, sizeof(perID),
stdin) fflush(stdin) // ?? ??? ???.
fputs("??? ?? ??? ", stdout) fgets(name,
sizeof(name), stdin) printf("???? ???
s\n", perID) printf("? ?
s\n", name) return 0
12
21-5 ??? ?? ??
  • ???? ??? ???? strlen ??
  • ???? ???? ??

include ltstdio.hgt size_t strlen(const char s)
?? ? 0, ?? ? EOF ??
include ltstring.hgt   char strcpy(char dest, const char src) char strncpy(char dest, const char src, size_t n)
?? ? ??? ???? ??? ??
13
21-5 ??? ?? ??
/ strlen.c / include ltstdio.hgt include
ltstring.hgt int main(void) char
str100 while(1) fgets(str,
sizeof(str), stdin) printf("???? ??
d \n", strlen(str)) return 0
14
21-5 ??? ?? ??
  • ???? ???? ??

include ltstring.hgt   char strcat(char dest, const char src) char strncat(char dest, const char src, size_t n)
?? ? ??? ???? ??? ?? 
?? 21-5
15
21-5 ??? ?? ??
/ strcat.c / include ltstdio.hgt include
ltstring.hgt int main(void) char
str130"Your favorite language is " // null ??
?? 27??. char str210 fputs("What is
your favorite computer lanaguage ? ", stdout)
fgets(str2, sizeof(str2), stdin)
strcat(str1, str2) printf("??? ??? s
\n", str1) return 0
16
21-5 ??? ?? ??
  • ???? ???? ??

include ltstring.hgt   int strcmp(const char s1, const char s2) int strncmp(const char s1, const char s2, size_t n)
?? ? ??? ???? ??? ?? 
?? ? ??
0?? ? ?(??) str1? str2 ?? ? ??
0 str1? str2? ??? ?? ??
0?? ?? ?(??) str1? str2 ?? ?? ??
? 21-2
17
21-5 ??? ?? ??
/ strcamp.c / include ltstdio.hgt include
ltstring.hgt char str1"ABC" char
str2"ABD" int main (void) int
result resultstrcmp(str1, str2)
if(resultgt0) puts("str1? str2?? ???
") else if(resultlt0) puts("str2?
str1?? ???") else puts("? ????
??? ????") return 0
18
21-5 ??? ?? ??
  • ???? ??? ???? ???
  • ?????? ??? ???? ???

include ltstdlib.hgt   int atoi(char ptr) //
???? int? ???? ?? long atol(char ptr) // ????
long? ???? ?? double atof(char str) // ????
double? ???? ??
include ltctypes.hgt   int toupper(int c) // ????
???? int tolower(int c) // ???? ????
Write a Comment
User Comments (0)
About PowerShow.com