?
This document uses PHP Chinese website manual Release
在頭文件<stdio.h>中定義 | ||
---|---|---|
int fputc(int ch,F(xiàn)ILE * stream); | ||
int putc(int ch,F(xiàn)ILE * stream); |
將字符寫入ch
給定的輸出流stream
。putc()
可能被實現(xiàn)為一個宏并且stream
不止一次地進(jìn)行評估,所以相應(yīng)的參數(shù)不應(yīng)該是帶有副作用的表達(dá)式。
在內(nèi)部,字符unsigned char
在被寫入之前被轉(zhuǎn)換。
CH | - | 字符被寫入 |
---|---|---|
流 | - | 輸出流 |
成功時,返回書面字符。
On failure, returns EOF
and sets the error indicator (see ferror()
) on stream
.
帶有錯誤檢查的putc。
#include <stdio.h>#include <stdlib.h> int main(void){ int ret_code = 0; for (char c = 'a'; (ret_code != EOF) && (c != 'z'); c++) ret_code = putc(c, stdout); /* Test whether EOF was reached. */ if (ret_code == EOF) if (ferror(stdout)) { perror("putc()"); fprintf(stderr,"putc() failed in file %s at line # %d\n", __FILE__,__LINE__-7); exit(EXIT_FAILURE); } putc('\n', stdout); return EXIT_SUCCESS;}
輸出:
abcdefghijklmnopqrstuvwxy
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.21.7.3 fputc函數(shù)(p:331)
7.21.7.7 putc函數(shù)(p:333)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.19.7.3 fputc函數(shù)(p:297)
7.19.7.8 putc函數(shù)(p:299)
C89 / C90標(biāo)準(zhǔn)(ISO / IEC 9899:1990):
4.9.7.3 fputc函數(shù)
4.9.7.8 putc函數(shù)