#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;
}