#include <stdio.h> int fclose(File *stream) stream : FILE 構造体へのポインタ
#include <stdio.h> int main() { long x,y; FILE *stream; x = 10; y = 20; /* ファイルのオープンとデータの出力 */ if ((stream = fopen("data","w")) == NULL) printf("The file 'data' was not opend\n"); else printf("The file 'data' was opend for output\n"); fprintf(stream, "%ld %ld\n", x, y); /* ファイルのクローズ */ if(fclose(stream)) printf("The file 'data' was not closed\n"); else printf("The file 'data' was closed\n"); /* ファイルのオープンとデータの入力 */ if ((stream = fopen("data","r")) == NULL) printf("The file 'data' was not opend\n"); else printf("The file 'data' was opend for input\n"); fscanf(stream,"%ld %ld\n", &x, &y); printf("x = %ld, y = %ld\n", x, y); return 0; }
The file 'data' was opend for output The file 'data' was closed The file 'data' was opend for input x = 10, y = 20
菅沼ホーム | 本文目次 | 演習問題解答例 | 付録目次 | 索引 |