Advertisement

Η ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 15 - ΣΥΝΑΡΤΗΣΕΙΣ ΕΙΣΟΔΟΥ (ΕΚΤΥΠΩΣΗ)

Teacher & Manager at Δημήτρης Ψούνης - Υπηρεσίες Εκπαίδευσης
Feb. 27, 2016
Advertisement

More Related Content

Slideshows for you(20)

More from Dimitris Psounis(20)

Advertisement

Η ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 15 - ΣΥΝΑΡΤΗΣΕΙΣ ΕΙΣΟΔΟΥ (ΕΚΤΥΠΩΣΗ)

  1. H C 15: / : . 1. 2. stdin 3. stdout 4. stderr . stdin 1. 2. getchar() 3. getch() 4. getche() 5. H ungetc() 6. gets() 7. fgets() 8. scanf() 9. fflush() !" A. ! " 1. # #!" $ # " C, % " & ' (streams). # ( # & ) % ) ( % "( . * ( & % & + ) " ) " : , ) # " (stdin) ) ) - + # ) )( # ( % . , ) # " (stdout) ) % . # . stdout stdin A. ! " 1. # $!" / C ( ) # ( # & ) ) ) ) % . " ) 2 #" " ) " ("0 " ) ((" # " ) ) /" ) # ) (( # " , ). stdout stdin printer DVD-ROM HARD DISK
  2. A. ! " 2. $ ) # " stdin !" H ANSI C ( " ) ) - #" ( % ) ) ") " # %(& C) + ) # & 5 " ) # ( ) C: 1 " * ) ) ( # DOS # & )(" ) & " . stdin # " ( # ( % stdout # " 1 stderr # " 1 stdprn* # " # )& # )& (LPT1) stdaux* # " 2 # 3 (COM1) A. ! " 2. $ ) # " stdin %!" / ( # . stdin « &( » ) " )( # ( % ) % . . $ scanf ) , - + # ) stdin, # + ) ) ) " " 1o . " % ) # ) " stdin % ) - ) # ) ( ) # " . 3 # (( ) + ) # " . stdin 11223 xyzw 223 A. ! " 3. $ ) # " stdout &!" stdout « &( » ) " ) % ) ( % . . . $ puts, ) stdout - ( ) " & # ( )& # ) - # stdout . stdout A. ! " 4. $ ) # " ( ' stderr. '!" $ stderr ) ( % )& stdout, ) % . ( # "( ) % . % ( ) % ( % % ( % ) ) ) % # ( (). . " , ) ( # , % ) # & #.().) # " ) ) "( ) - (( , # ) % , C + - # , % % & ) % , ) ( . stderr
  3. B. ! 1. 0 (!" H C ) " ) % ) )( # ( % . - # # # & & ) ) ") " ) 0 : # ) )( # ( % " " ) & ' ) # # ) % stdin ) ' Enter, # # ) )( # ( % ) % # stdin. , # # ) # # & )( # ( % ) - (( # . , # # ) - ( # & B. ! 1. 0 )!" ) ' ) ( ) . : ! " # $ % & # $ & *+,-./0 1 ! 2 3 !" 456 456 7,89:;. *+,-. 1 ! 2 3 !" <=> <=> -:?9:;. *+,-.+ 1 ! 2 3 !" <=> @ A> -:?9:;. B?*+,- A C D 2 3 E E 7,89:;. *+,7 1 1 @A> @A> 7,89:;. F*+,7 1 1 @A> @A> 7,89:;. 7-/?F 1 1 456 456 7,89:;. B. ! 2. $ getchar() !" , ) & ) getchar : / " - -( # : $ - + " # ) stdin # ) ". ASCII #& # . % ) # # & , " ) )( # ( % Enter % # & # stdin. - (( # ) )( # ( % . int getchar() stdio.h B. ! 2. $ getchar() !" , ) # & ) % # getchar 1 % - ( # " ) Enter. $ ) # stdin # ) ) % ( ) Enter. /* getchar.c: Epideiksi tis entolis getchar */ #include <stdio.h> main() { char c; c=getchar(); while(c!='x') { printf("%c,",c); c=getchar(); } printf("%c.",c); }
  4. B. ! 3. $ getch () #!" , ) & ) getch : / " - -( # : $ - + " # ) stdin # ) ". ASCII #& # . % & ) # # & , ) ) " # ) # stdin. ) - (( # ) )( # ( % !! ! , # . ( conio.h " ANSI C, ) ) ) ) %(& . DEV-C++ & ' , ) ) # # ! int getch () conio.h B. ! 3. $ getch () $!" , ) # & ) % # getch 1 )( # ( % - ( . $ 4 ) # stdin # )( # ( % # # - + " & ) getch() /* getch.c: Epideiksi tis entolis getch */ #include <stdio.h> #include <conio.h> main() { char c; c=getch(); while(c!='x') { printf("%c,",c); c=getch(); } printf("%c.",c); } B. ! 4. $ getche () !" , ) & ) getche : / " - -( # : $ ( % ) getch() . ) - (( # ) )( # ( % . %(& # # (" ) % getche.c ) ( % # . ) ( getch. int getche () conio.h B. ! 4. $ getche () %!" , ) # & ) % # getche 1 )( # ( % - ( . $ 4 ) # stdin # )( # ( % # # - + " & ) getche(). 5 )( # ( % # ) - (( . /* getche.c: Epideiksi tis entolis getch */ #include <stdio.h> #include <conio.h> main() { char c; c=getche(); while(c!='x') { printf("%c,",c); c=getche(); } printf("%c.",c); }
  5. B. ! 5. $ ungetc() &!" , ) & ) ungetc : / " - -( # : $ ungetc ( 0 # ch ) fp 3 ) , ) # # " ) # % ’ & 2 ) # . " ( 0 ) stdin, )( % . & stdin. $ ) # # ) ) stdin # ch ) - . ) % ) . -(") )& ) ungetc. int ungetc(int ch, FILE *fp) stdio.h B. ! 5. $ ungetc() '!" , ) # & ) % # ungetc ( # ( % - ( ) ) " ( . % m # ) " stdin, ( %& ) ) " " # stdin. /* ungetc.c: Epideiksi tis entolis ungetc */ #include <stdio.h> main() { char c; c=getchar(); while(c!='n') { printf("%c",c); c=getchar(); if (c=='m') { printf("%c",c); ungetc('!',stdin); } } } B. ! 6. $ gets() (!" , ) & ) gets : / " - -( # : ( %# # " ) % . $ - + - ( ) stdin " # ‘n’ ) # ‘0’ # ) # - ( str ) " & " & . . % # ) ( % ) , ) ". NULL (# # ), (( ' ) ". # str. 1 " ) gets : 5) buffer - ( () # # & ) ) " # # . char *gets(char *str) stdio.h gets(buffer); B. ! 7. $ fgets() )!" ((" . " " ) -( gets, - ( ) ) " # ' % ) # ( " ) % . H fgets " ( ) -( . , ) & ) fgets : / " - -( # : $ - + - ( ) fp # ) # str " : - + # ‘n’ ) # ‘0’ - n-1 # . , ) " # ‘0’ "( # + . )( ( % fgets - + # ) - ) # " & - ( ) & . , ) % ) . # & ) ) & char *fgets(char *str, int n, FILE *fp) stdio.h
  6. B. ! 7. $ fgets() !" , ) # & ) % # fgets ( # ( % - ( # % ( 10 # ) Enter. ) . ) % . /* fgets.c: Epideiksi tis entolis fgets */ #include <stdio.h> #define N 10 main() { char buffer[N]; while(1) { fgets(buffer,N,stdin); printf("Eisodos: %sn",buffer); } } B. ! 8. $ scanf() !" , scanf " ( . " . %& )( ) " , # ( # " ) # ) % scanf ) " : 5) 1 - ( . ) # ) + ( ) & -( ' ) " ) % # " : , ) " - ( . ) ) " ) ) " - ( . ) ) ) ") " : ) - ( & # & )( # ( % . ' % # ) # & # & stdio.h scanf("%x",& ); B. ! 8. $ scanf() #!" 9: « %&% / " & » ) " scanf. & ) " & #" ) ' ' # + # ) ) - ( ) % - # ) & # & ). : % '( $ ) ! G;;;H 1 I ! 2 3 G H C I " 3 C; ! " 1 2 3 3 ! J G H K J ; GL;;;H M C" G H ! 2 3 3 ! J G H C I " 3 C B. ! 8. $ scanf() $!" , ) # & ) % # & ) )(" ) ' ) % : ( # ( % # # (" ) % % . ) ) " # ) ) ) . /* scanf.c: Epideiksi tis entolis scanf */ #include <stdio.h> main() { char buffer[80]; printf("Eisagete simvoloseira: "); scanf("%[abcdef]",buffer); printf("Diavastike: %sn",buffer); printf("Eisagete simvoloseira: "); scanf("%[^abcdef]",buffer); printf("Diavastike: %s",buffer); }
  7. B. ! 9. $ fflush() !" 5 # ( #( scanf ( - ) stdin ) % - ) & " & ) . % ) % " ( : / % : , - + 15 # x, % # # - + 20 # y.1 ) ( ) # ) " stdin % ) - . )' ) " ) # # ) . )" ) % ) ") ) ) " " " ) # ) # stdin ) # ) - . # # n ) " ) - scanf. ( % + fflush. stdio.h scanf("%d",&x); scanf("%d",&y); 15 20 30 B. ! 9. $ fflush() %!" , ) & ) fflush : / " - -( # : $ « + » stdin ) # ) " ) . %(& ) % ) . ( ) ( & ) fflush int fflush(FILE *fp) stdio.h B. ! 9. $ fflush() &!" /* fflush_wrong.c: Epideiksi tis entolis fflush */ #include <stdio.h> main() { int x,y,z; char c; printf("Dwse enan tripsifio arithmo:"); scanf("%1d%1d%1d", &x,&y,&z); printf("Epelekse M-Monades,D-Dekades,E-Ekatontades: "); scanf("%c",&c); B. ! 9. $ fflush() '!" switch(c) { case 'M': printf("Monades=%d",z); break; case 'D': printf("Dekades=%d",y); break; case 'E': printf("Ekatontades=%d",z); break; default: printf("Lathos eisodos!"); } }
  8. 2. # 1. ) # . ( ( ) (!" 0 " ) % ) "( : 1. - + - ( ) )( # ( % ( 4 "( ) # # ) ) # # 4 "( . + ) )( # ( % ) 2. . + - ( ) # # # " # ) # . ( # . 2. # 2. - - ( ' #)!" 0 " ) % ) : 1. (' " ) # # & ( string) %" 10. 2. 6 ) )( # ( % - ( . 3. - ( & string ) # # ) - (( « - ( - # » # )' . 4. - ( & string ) # " ) ) ) # # ) - (( « - ( - # » # )' " ) « ' » string. 4 # + stdin ) # ) " ) .
Advertisement