next up previous contents
Next: 字串 Up: 標準輸入與輸出 Previous: 前言   Contents

單一字元

  1. 範例:輸入一個字元。
    [dywang@dyw219 zzz]$ vim stdio1.c
    [dywang@dyw219 zzz]$ cat stdio1.c
    #include <stdio.h>
    
    main () {
    	char c;
    
    	printf( "Enter a character: ");
    	c = getchar( );
    	printf( "You entered: ");
    	putchar(c);
    	printf( "\n");
    }
    
  2. 編譯
    [dywang@dyw219 zzz]$ gcc -o stdio1 stdio1.c
    
  3. 執行結果
    [dywang@dyw219 zzz]$ ./stdio1
    Enter a character: A
    You entered: A
    



De-Yu Wang 2019-08-14