使用文件存储要怎么弄

 

按题目要求创建结构体数组,

文件操作参考代码如下:

#include "stdio.h"

struct SNAKE
{
	int direction;
	int life;
	int node;
	int level;
	int score;
}snake;
struct FOOD{
	int x;
	int y;
	int yes;	
}food;
void main()
{
  FILE *fp;
  snake.direction=1;
  snake.life=1;
  snake.node=3;
  snake.level=1;
  snake.score=0;
  
  food.x=100;
  food.y=200;
  food.yes=1;
  fp = fopen("d:\\snake.dat","wb+");
  if(fp==NULL){
  	printf("can not open file.\n");
  	exit(0);
  }
  fwrite(&snake,sizeof(struct SNAKE),1,fp);
  fwrite(&food,sizeof(struct FOOD),1,fp);
  fclose(fp);
}