?????(I/O) - PowerPoint PPT Presentation

About This Presentation
Title:

?????(I/O)

Description:

Title: The C Programming Language Author: jyyang Last modified by: hsguo Created Date: 7/2/1995 1:21:06 PM Document presentation format: A4 (210x297 ) – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 16
Provided by: jyy1
Category:
Tags: file

less

Transcript and Presenter's Notes

Title: ?????(I/O)


1
?????(I/O)
2
???????
  • ????(Standard Output, stdout) ?????????.
  • ????((Standard Input, stdin) ?????????.

? ? ???? ? ? ???
? ? ? ? ? ? printf ??????????????? stdio.h
? ? ? ? ? ? puts ?????? stdio.h
? ? ? ? ? ? putchar ?????? stdio.h
? ? ? ? ? ? putch ?????? conio.h
? ? ? ? ? ? scanf ??????????????? stdio.h
? ? ? ? ? ? gets ????????? stdio.h
? ? ? ? ? ? getchar ????????? stdio.h
? ? ? ? ? ? getche ??????????????? conio.h
? ? ? ? ? ? getch ??????????????? conio.h
3
?????(printf??)
  • printf??????????????????,??????
  • printf(????")
  • ??
  • printf("Every day is working day.")
  • printf("This number is 2.")
  • ????

4
?????(printf??)-????????
  • printf??????????????????,??????
  • printf( ???? ??? ,??1,??2, )
  • ???????????(???)?????.
  • ???
  • ?????????,??????
  • ??
  • printf(I have d cats., num)
  • printf(This number is d.,2)
  • printf(d,1/3)

??num3,???? I have 3 cats.
??? This is number two 2.
??? 0
5
????
  • ???DevC,?????????????.
  • includeltstdio.hgt
  • int main(void)
  • int a2
  • int b3
  • printf("I have d dogs and d cats\n", a, b)
  • system(pause")
  • return 0
  • ????????

??????????
6
??????(scanf??)
  • scanf??????????????,???????,??????
  • scanf(???,??1,??2,)
  • ????????????
  • ??
  • includeltstdio.hgt
  • int main(void)
  • int x,y
  • printf("Please input two numbers\n")
  • scanf("d d" ,x, y)
  • printf("resultsd, d",x,y)
  • system("pause")
  • return 0
  • /?????????????,???????????(????Tab?)??,?Ente
    r?,??????,?????????./

???????,????????????
7
??????(scanf??)
  • includeltstdio.hgt
  • int main(void)
  • int x,y
  • printf("Please input two numbers\n")
  • scanf("d,d",x,y)
  • printf("resultsd,d",x,y)
  • system("pause")
  • return 0
  • /??????????????,??????,?????????/
  • ???????????????,????Enter?,???????

8
printf()?scanf()????????
printf()?? scanf() ?? ????
c c ??
d d ?????
o o ?????
x x ??????
s s ??
f e ??(?????)
lf lf ??????(l???????)
e f ??(??e??)
9
???????
?????????????
getch( ) getche( ) getchar( )
????????? ? ? ?
?? Enter ? ?? ?? ?
?????? ??? ?? ??
include ? ? ?
?????? conio.h conio.h stdio.h
????? ??getch() ??getche() ??getchar()
10
???????
  • ??????
  • putchar()
  • ????????????,????????????(stdio.h)
  • ????? putchar(??)
  • putch()
  • ????????????,??????????????(conio.h)?????
    putch(??)

11
??????----??
  • / ???????????? /
  • include ltstdio.hgt
  • includeltconio.hgt
  • void main(void)
  • char ch1,ch2,ch3
  • printf(Please enter two characters\n)
    /?????????,??????buffer?/
  • ch1getche()
  • ch2getche()
  • printf("\nThe first character is\n")
    /???????/
  • putchar(ch1)
  • printf("\nThe second character is\n")
    /???????/
  • putchar(ch2)
  • printf("\nPlease input a character\n")
    /????????,???enter????????/
  • ch3getchar()
  • printf("\nThe third character is\n")
  • putchar(ch3)
  • printf("\n\n\n")
  • system("pause")

12
????????----??2
  • / ?????? ,??????ASCII?/
  • include ltstdio.hgt
  • include ltstdlib.hgt
  • int main(void)
  • char ch / ???????? /
  • / ?????????????? /
  • printf("Please input a character ")
  • scanf("c",ch)
  • / ????????????ASCII? /
  • printf("chc , ASCII code is d. \n", ch, ch)
  • system("pause")
  • return 0 / ?????? /

13
?????????
  • includeltstdio.hgt
  • int main(void)
  • int num
  • char ch
  • printf("Please input a integer\n")
  • scanf("d",num)
  • printf("Please input a character")
  • scanf("c",ch)
  • printf("\nnumd,ASCII code of
    characterd\n",num,ch)
  • system("pause")
  • return 0

??ch??????enter(????)???????????????
14
?????????---????
  • 1.?scanf()??c?????????????????.
  • 2.??fflush(stdin)???????????.
  • includeltstdio.hgt
  • int main(void)
  • int num
  • char ch
  • printf("Please input a integer\n")
  • scanf("d",num)
  • fflush(stdin)
  • printf("Please input a character")
  • scanf("c",ch)
  • printf("\nnumd,ASCII code of
    characterd\n",num,ch)
  • system("pause")
  • return 0

15
????????----??3
  • / ?????? /
  • include ltstdio.hgt
  • include ltstdlib.hgt
  • int main()
  • char name10 / ?????? /
  • / ?????????????? /
  • printf("What's your name ")
  • scanf("s",name) /????,??????name???/
  • printf("Hi s , How are you ?\n" , name)
    /???????/
  • system("pause")
  • return 0 / ?????? /
Write a Comment
User Comments (0)
About PowerShow.com