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 55 56 57 58 59 60 61 62 63 64 65 66
|
can someone explain the function below to me
void readFile()
{
ifstream read("bs.txt");
ofstream fout("tmp.txt");
int roomNo, levelNo, time, duration,x;
char date[10],subject[30],lecturer[30],temp[30],c;
read>>x;
read.seekg(1,ios::cur);
read.get(c);
while(read)
{
if(c!=10)
c-=x*10;
fout.put(c);
read.get(c);
}
read.clear();
fout.close();
read.close();
read.open("tmp.txt");
//receiving values from file and storing in variables
read.getline(temp,30,':');
ID = atoi(temp);
read.getline(temp,30,':');
roomNo = atoi(&temp[5]);
read.getline(temp,30,':');
levelNo = atoi(&temp[6]);
read.getline(temp,30,':');
strcpy(date,temp);
read.getline(temp,30,':');
time = atoi(temp);
read.getline(temp,30,':');
duration = atoi(temp);
read.getline(temp,30,':');
strcpy(subject,temp);
read.getline(temp,30,'\n');
strcpy(lecturer,temp);
while(read)//while data is read from file
{
add(ID,roomNo,levelNo,time,duration,date,subject,lecturer);
read.getline(temp,30,':');
if(!read)//if there is file input error
break;
ID = atoi(temp);
read.getline(temp,30,':');
roomNo = atoi(&temp[5]);
read.getline(temp,30,':');
levelNo = atoi(&temp[6]);
read.getline(temp,30,':');
strcpy(date,temp);
read.getline(temp,30,':');
time = atoi(temp);
read.getline(temp,30,':');
duration = atoi(temp);
read.getline(temp,30,':');
strcpy(subject,temp);
read.getline(temp,30,'\n');
strcpy(lecturer,temp);
}
read.close();
remove("tmp.txt");
}
|