-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_from_file.cpp
More file actions
54 lines (51 loc) · 963 Bytes
/
read_from_file.cpp
File metadata and controls
54 lines (51 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
extern short record_start[][9];
extern short record_whose_turn[100];
extern short record_i[100];
extern short record_j[100];
bool read_from_file()//读盘
{
FILE *fp;
char filename[30],ch='0';
cout<<"请输入您之前保存的文件名,以“file”开始,以“.txt”结束,不超过30个字符。"<<endl;
scanf("%s",filename);
if((fp=fopen(filename,"r"))==NULL)
{
printf("无法打开该文件,请重试。\n");
return 0;
}
ch=fgetc(fp);
record_start[0][0]=ch-'0';
int i=0,j=0;
while(true)
{
j++;
if(j==9)
{
j=0;
i++;
ch=fgetc(fp);
}
if(i==9)
break;
ch=fgetc(fp);
record_start[i][j]=ch-'0';
}
for(i=0;i<100;i++)
{
ch=fgetc(fp);
record_whose_turn[i]=ch-'0';
ch=fgetc(fp);
record_i[i]=ch-'0';
ch=fgetc(fp);
record_j[i]=ch-'0';
ch=fgetc(fp);
}
fclose(fp);
return 1;
}