em có 1 bài tập mà nghĩ mãi ko hiểu nó bị lỗi chỗ nào phiền mấy anh pro giúp với
em tạo đc 1 file tai khoản .dat trong đó chứa nội dung thông tin của nhiều tài khoản
song em tạo 1 hàm để kiểm tra thông tin đăng nhập nhưng chỉ kiểm tra đc 1 tài khoản duy nhất đầu tiên
ví dụ như giờ em tạo 5 tài khoản lần lượt là : (sotk:1 mapin1)(sotk:2 mapin2)(sotk:3 mapin3)
(sotk:4 mapin4)(sotk:5 mapin5) nhưng lúc check thì nó chỉ cho kết quả đăng nhập thành công của (sotk:1 mapin1) còn 4 sotk còn lại nó báo sai => nếu bỏ chỗ else o? chỗ ham searchid() nếu bỏ di thi no' kiem tra binh thuong cac sotk con lai nhung neu bo thi no ko thong bao dc khi nhap sotk hoac mapin sai va` cho quay lai nhap. lai
Mong Các Anh Chỉ giáo giúp vì em cũng mới học lập trình nên cũng biết mình lỗi ở chỗ nào
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
FILE *f;
struct create
{
int sotk;
int mapin;
char tenkh[30];
float tien;
char ntns[20];
char gtinh[6];
int cmtnd[18];
};
void searchid()
{
struct create st;
f=fopen("mycard.dat","rb");
int sID;
int sMP;
char flag='y',found;
do
{
while(flag=='y')
{
printf("testID: ");
fflush(stdin);
scanf("%d",&sID);
printf("testPIN: ");
fflush(stdin);
scanf("%d",&sMP);
while(fread(&st,sizeof(struct create),1,f)==1)
{
if(sID==st.sotk && sMP==st.mapin )
{
printf("\nChuc Mung Ban Dang Nhap Thanh Cong !");
// return true;
getch();
flag='n';
clrscr();
}
else
/*bo? di thi no' kiem tra binh thuong cac sotk con lai nhung neu bo thi no ko thong bao dc khi nhap sotk hoac mapin sai va` cho quay lai nhap. lai*/
{
printf("\nSo Tai Khoan Hoac Ma Pin Ko Hop Le. !");
printf("\nAn Enter De Nhap Lai !");
flag='y';
fseek(f,(long)sizeof(struct create),1);
getch();
}
}
}
}while(flag=='y');
}
struct trave
{
char sotk[14];
int mapin[9];
};
void create()
{
char tenfile[30];
struct create create1 ;
int size=sizeof(struct create);
printf("\nNhap So Tai Khoan:");
fflush(stdin);
scanf("%d",&create1.sotk);
printf("\nNhap Ten khach hang :");
fflush(stdin);
gets(create1.tenkh);
printf("\nNhap Ma Pin :");
scanf("%d",&create1.mapin);
printf("\nNhap So Tien :");
scanf("%f",&create1.tien);
printf("\nNgay thang nam sinh :");
fflush(stdin);
gets(create1.ntns);
printf("\nGioi Tinh (nam/nu) :");
fflush(stdin);
gets(create1.gtinh);
printf("\nNhap So Chung Minh Thu :");
scanf("%d",&create1.cmtnd);
// rewind(f)
f=fopen("mycard.dat","a+b");
fwrite(&create1,size,1,f);
// fseek(f,(long)(size),1);
//input(st);
//write(st,tenfile);
//fclose(f);
printf("\nCreate Hoan Tat !....");
printf("\nBam Phim Bat Ky De Ket Thuc !....");
getch();
exit(1);
}
menu()
{
printf("\n1. Kiem tra so du tai khoan.");
printf("\n2. Rut tien.");
printf("\n3. Chuyen Khoan.");
printf("\n4. Doi Ma Pin.");
printf("\n0. Thoat.");
}
void main()
{
// menu();
//create(); /*de test tao. tai khoan*/
searchid(); /*khai bao ham kiem kiem tra so TK va MaPIn*/
getch();
}