nếu mình code ntn
void readfile(List &l)
{
char buffer[100000];
buffer[0] = '\0';
ifstream ifs("fixedinput.txt", ifstream::in);
while (strlen(buffer) <=0)
{
if (ifs.eof()) break;
ifs.getline(buffer, 100000, '#');
if (buffer!=NULL)
{
nhanvien*nv = new nhanvien();
nv->manv = strtok(buffer, "\n");
nv->ho = strtok(NULL, "\n");
nv->ten = strtok(NULL, "\n");
nv->donvi = strtok(NULL, "\n");
nv->chucvu = strtok(NULL, "\n");
nv->sinhnhat.ngay = atoi(strtok(NULL, "/"));
nv->sinhnhat.thang = atoi(strtok(NULL, "/"));
nv->sinhnhat.nam = atoi(strtok(NULL, "\n"));
nv->quequan = strtok(NULL, "\n");
nv->diachi = strtok(NULL, "\n");
nv->mail = strtok(NULL, "\n");
nv->sdt = strtok(NULL, "\n");
nv->batdau.ngay = atoi(strtok(NULL, "/"));
nv->batdau.thang = atoi(strtok(NULL, "/"));
nv->batdau.nam = atoi(strtok(NULL, "\n"));
/*wcout << nv->manv << endl;
wcout << nv->ho << endl;
wcout << nv->ten << endl;
cout << nv->donvi << endl;
cout << nv->chucvu << endl;
cout << nv->sinhnhat.ngay << "/" << nv->sinhnhat.thang << "/" << nv->sinhnhat.nam << endl;
cout << nv->quequan << endl;
cout << nv->diachi << endl;
cout << nv->mail << endl;
cout << nv->sdt << endl;
cout << nv->batdau.ngay << "/" << nv->batdau.thang << "/" << nv->batdau.nam << endl;*/
char*s = strtok(NULL, "#");
int i = 0;
while (s != NULL)
{
char*temp = strtok(s, "\n");
s = strtok(NULL, "#");
nv->time[i].ngay = atoi(strtok(temp, "/"));
nv->time[i].thang = atoi(strtok(NULL, "/"));
nv->time[i].nam = atoi(strtok(NULL, ","));
nv->time[i].gioden = atoi(strtok(NULL, ":"));
nv->time[i].phutden = atoi(strtok(NULL, ","));
nv->time[i].giove = atoi(strtok(NULL, ":"));
nv->time[i].phutve = atoi(strtok(NULL, "\n"));
i++;
}
nv->dodai = i;
Node*p = makeNode(nv);
addHead(l, p);
}
}
ifs.close();
}`
thì chỉ đọc đên phần có dấu # đầu tiên là ngừng vậy có cách nào đọc đến hết file ko
còn nếu code ntn
`
void readfile(List &l)
{
char buffer[100000];
buffer[0] = '\0';
ifstream ifs("fixedinput.txt", ifstream::in);
while (strlen(buffer) <=0)
{
if (ifs.eof()) break;
ifs.getline(buffer, 100000, '#');
if (buffer!=NULL)
{
nhanvien*nv = new nhanvien();
nv->manv = strtok(buffer, "\n");
nv->ho = strtok(NULL, "\n");
nv->ten = strtok(NULL, "\n");
nv->donvi = strtok(NULL, "\n");
nv->chucvu = strtok(NULL, "\n");
nv->sinhnhat.ngay = atoi(strtok(NULL, "/"));
nv->sinhnhat.thang = atoi(strtok(NULL, "/"));
nv->sinhnhat.nam = atoi(strtok(NULL, "\n"));
nv->quequan = strtok(NULL, "\n");
nv->diachi = strtok(NULL, "\n");
nv->mail = strtok(NULL, "\n");
nv->sdt = strtok(NULL, "\n");
nv->batdau.ngay = atoi(strtok(NULL, "/"));
nv->batdau.thang = atoi(strtok(NULL, "/"));
nv->batdau.nam = atoi(strtok(NULL, "\n"));
/*wcout << nv->manv << endl;
wcout << nv->ho << endl;
wcout << nv->ten << endl;
cout << nv->donvi << endl;
cout << nv->chucvu << endl;
cout << nv->sinhnhat.ngay << "/" << nv->sinhnhat.thang << "/" << nv->sinhnhat.nam << endl;
cout << nv->quequan << endl;
cout << nv->diachi << endl;
cout << nv->mail << endl;
cout << nv->sdt << endl;
cout << nv->batdau.ngay << "/" << nv->batdau.thang << "/" << nv->batdau.nam << endl;*/
char*s = strtok(NULL, "#");
int i = 0;
while (s != NULL)
{
char*temp = strtok(s, "\n");
s = strtok(NULL, "#");
nv->time[i].ngay = atoi(strtok(temp, "/"));
nv->time[i].thang = atoi(strtok(NULL, "/"));
nv->time[i].nam = atoi(strtok(NULL, ","));
nv->time[i].gioden = atoi(strtok(NULL, ":"));
nv->time[i].phutden = atoi(strtok(NULL, ","));
nv->time[i].giove = atoi(strtok(NULL, ":"));
nv->time[i].phutve = atoi(strtok(NULL, "\n"));
i++;
}
nv->dodai = i;
Node*p = makeNode(nv);
addHead(l, p);
}
}
ifs.close();
}`
thì kết quả mong muốn khi đưa dữ liệu vào danh sách in ra là ntn
thực tế thì ra ntn
còn đây dữ liệu đầu vào
1
Tran Van
A
BKCorporation
Chu tich
10/01/1980
Ha Noi
So 1, Ta Quang Buu
[email protected]
0123456789
22/02/2016
22/02/2016,7:49,18:00
22/02/2016,7:49,18:00
23/02/2016,7:51,18:05
24/02/2016,7:45,12:30
25/02/2016,7:45,12:30
26/02/2016,7:45,12:30
27/02/2016,7:45,12:30
28/02/2016,7:45,12:30
29/02/2016,7:45,12:30
2
Nguyen Thi
B
BKFood
Giam doc
12/02/1981
Ha Noi
So 10 Bach Khoa
[email protected]
012341234
15/04/2016
15/04/2016,7:49,18:00
16/04/2016,7:51,18:05
16/04/2016,7:51,18:05
25/02/2016,7:45,12:30
26/02/2016,7:45,12:30
27/02/2016,7:45,12:30
3
Nguyen Thi
C
BKTech
Giam doc
12/02/1981
Ha Noi
So 10 Bach Khoa
[email protected]
012341234
15/04/2016
15/04/2016,7:49,18:00
16/04/2016,7:51,18:05
16/04/2016,7:51,18:05
25/02/2016,7:45,12:30
26/02/2016,7:45,12:30
27/02/2016,7:45,12:30
4
Nguyen Thi
D
BKTech
Giam doc
12/02/1981
Ha Noi
So 10 Bach Khoa
[email protected]
012341234
15/04/2016
15/04/2016,7:49,18:00
16/04/2016,7:51,18:05
16/04/2016,7:51,18:05
25/02/2016,7:45,12:30
26/02/2016,7:45,12:30
27/02/2016,7:45,12:30
cấu trúc dữ liệu sử dụng là dslk đôi
ai biết mong chỉ cho vì sắp đến deadline


83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?