■ソースコード
#include <stdio.h>
#include <stdlib.h>
int main(void){
FILE *fp; // ファイル構造体
int dt = 12345; // ゲームのスコアと仮定
// 【手順1】ファイルを開く
fp = fopen("report.html","w");// "w" で出力指定
// 例外処理
if(fp == NULL){
printf("出力ファイルを開けません\n");
exit(1);
}
// 【手順2】ファイルに出力
fputs("<html><body>",fp);
fprintf(fp,"score = <b>%d</b>",dt);
fputs("</body></html>",fp);
// 【手順3】ファイルを閉じる
fclose(fp);
return 0;
}
■実行結果
>hellofilewrite.exe
#report.html に以下の内容のファイルが出力される
<html><body>score = <b>12345</b></body></html>