函式
<cstdio>

fputc

int fputc ( int character, FILE * stream );
將字元寫入流
將一個字元寫入並推進位置指示器。

該字元被寫入到內部位置指示器所指示的位置,然後該指示器自動向前移動一位。

引數

character
要放回的字元的int提升為 int 型的待寫入字元。
該值在放回時被內部轉換為unsigned char寫入時。
stream
指向一個 FILE 物件的指標,該物件標識一個輸出流。

返回值

成功時,返回寫入的字元
如果發生寫入錯誤,則返回 EOF 並設定錯誤指示器 (ferror)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* fputc example: alphabet writer */
#include <stdio.h>

int main ()
{
  FILE * pFile;
  char c;

  pFile = fopen ("alphabet.txt","w");
  if (pFile!=NULL) {

    for (c = 'A' ; c <= 'Z' ; c++)
      fputc ( c , pFile );

    fclose (pFile);
  }
  return 0;
}

該程式建立一個名為alphabet.txt的檔案,並向其中寫入ABCDEFGHIJKLMNOPQRSTUVWXYZ

另見