當前位置:編程學習大全網 - 源碼下載 - 請問:關於C語言中getc(stdin) 讀取鍵盤緩沖區的問題?

請問:關於C語言中getc(stdin) 讀取鍵盤緩沖區的問題?

getc(stdin)每次只能從緩沖區讀取壹個 字符,但是遇到回車符就結束了。連續從緩沖區讀取循環此段代碼。同樣以回車結束。#include<stdio.h>void main(void)

{while(1){

char a;

a=getc(stdin);

printf("%c",a);}} 這是編譯器內部定義的函數,他在頭文件裏的定義可以再函數名上擊右鍵選getc定義查看,但是內部實現看不到。下面是截取了stdio.h裏的壹段定義。

_CRTIMP int __cdecl _flushall(void);

_CRTIMP FILE * __cdecl fopen(const char *, const char *);

_CRTIMP int __cdecl fprintf(FILE *, const char *, ...);

_CRTIMP int __cdecl fputc(int, FILE *);

_CRTIMP int __cdecl _fputchar(int);

_CRTIMP int __cdecl fputs(const char *, FILE *);

_CRTIMP size_t __cdecl fread(void *, size_t, size_t, FILE *);

_CRTIMP FILE * __cdecl freopen(const char *, const char *, FILE *);

_CRTIMP int __cdecl fscanf(FILE *, const char *, ...);

_CRTIMP int __cdecl fsetpos(FILE *, const fpos_t *);

_CRTIMP int __cdecl fseek(FILE *, long, int);

_CRTIMP long __cdecl ftell(FILE *);

_CRTIMP size_t __cdecl fwrite(const void *, size_t, size_t, FILE *);

_CRTIMP int __cdecl getc(FILE *);//////////////////////////這裏定義了getc();

_CRTIMP int __cdecl getchar(void);

getc()中的參數FILE定義:#ifndef _FILE_DEFINED

struct _iobuf {

char *_ptr;

int _cnt;

char *_base;

int _flag;

int _file;

int _charbuf;

int _bufsiz;

char *_tmpfname;

};

typedef struct _iobuf FILE;

#define _FILE_DEFINED

#endif

  • 上一篇:長假去新疆旅遊的避雷攻略
  • 下一篇:隨機視頻api接口源代碼
  • copyright 2024編程學習大全網