Code:
#include<stdio.h>#include<stdlib.h>
#include<time.h>
#include<string.h>
//Ham in ra cac bien cua strung bt theo lenh in nhung den truoc khi ghi lai vao file thi cac bien bi dinh voi nhau
// va 1 so bien bi mat gia tri
typedef struct {
char id[14];
char pincode[6];
char name[50];
char date[26];
int status;
float sodu;
}thechinh;
void line();
void hienthi();
void taomathe();
void taopincode();
int ngaythang();
void uppername();
void nhapten();
thechinh makeCard();
FILE *f;
char path[30];
int main()
{
int i,chon,len=0;
thechinh listcard[100];
fflush(stdin);
char filename[100];
do
{
chon = Menu();
switch(chon)
{
case 1:
system("cls");
listcard[len] = makeCard();
len++;
break;
case 2:
changeInfo();
break;
default:
break;
}
}while(chon!=3);
}
int Menu()
{
fflush(stdin);
char *MenuItem[] = {"1. Tao moi ma the","2. Cap nhat thong tin chu the","3. Thoat"};
int i,choice;
for(i=0;i<2;i++)
{
printf("%s\n",MenuItem[i]);
}
printf("Chon chuc nang can su dung: ");
fflush(stdin);
scanf("%d",&choice);
return choice;
}
thechinh makeCard()
{
int i;
char chon,file[15];
thechinh mycard;
mycard.sodu = 1000000;
mycard.status = 1;
fflush(stdin);
printf("=====Chuong trinh tao moi ma the ATM=====");
printf("\nNhap vao ho va ten cua chu the");
ngaythang(mycard.date);
nhapten(mycard.name);
system("cls");
line();
printf("Ho va ten: %s",mycard.name);
taomathe(mycard.id);
line();
printf("ID card : ");
printf("%s",mycard.id);
line();
taopincode(mycard.pincode);
printf("Pincode :");
printf("%s",mycard.pincode);
line();
printf("So du : %.2f VND",mycard.sodu);
line();
//In here have problem variable mycard.id change value to combined mycard.id and mycard.pincode
// mycard.name change value to NULL
printf("%s",mycard.id);
printf("+%-25s+\n", "-------------------------");/*
char filename[30], dat[4]=".dat", tempFile[15], pathName[] = "Accounts\\",id[15];
strcpy(filename,mycard.id);
strcat(filename,dat);
strcat(pathName,filename);*/
f = fopen("213.dat","wb");
fwrite(&mycard, sizeof(thechinh), 1, f);
fclose(f);
}
void doitenfile(char *a,char *b)
{
strcat(a,b);
}
changeInfo()
{
printf("Test");
}
//Ham su dung de tao ma the su dung 3 chuoi de ghep lai do moi lan chi tao ra dc 5 so random
void taomathe(char *ID)
{
char code2[5], code3[5], code4[4], realcode[15];
int num1, num2, num3, num4;
srand(time(NULL));
//lay random 5 so
num1 = rand()%10001+32768;
num2 = rand()%10001+32768;
//lay random 4 so
num3 = rand()%100+999;
//chuyen doi tu kieu int thanh string
itoa(num3,code4,10);
itoa(num2,code3,10);
itoa(num1,code2,10);
//ghep cac chuoi lai cho du 14 so
strcpy(realcode,code2);
strcat(realcode,code3);
strcat(realcode,code4);
strcpy(ID,realcode);
}
//Ham su dung de tao pincode ghep 2 chuoi do 1 lan chi tao ra dc 3 so random
void taopincode(char *pass)
{
int num1, num2, num3;
char code1[5], code2[1], ranPW[6];
srand(time(0));
num1 = rand() % 10000+9999;
num2 = rand() % 10;
itoa(num2,code2,10);
itoa(num1,code1,10);
strcpy(ranPW,code1);
strncat(ranPW,code2,1);
strcpy(pass, ranPW);
}
//Ham lay ra ngay thang
int ngaythang(char *p)
{
time_t time_raw_format;
time (&time_raw_format);
//ctime lay ra ngay thang hien tai tra ve theo kieu string
strcpy(p,ctime(&time_raw_format));
}
void line()
{
printf("\n+%-25s+\n", "-------------------------");
}
//Ham de nhap ten
void nhapten(char ten[50])
{
int i;
fflush(stdin);
gets(ten);
for(i=0;i<5;i++)
{
uppername(ten);
}
}
//Doi thanh chu hoa
void uppername(char name_arr[])
{
int x;
for(x=0;name_arr[x] != '\0';x++)
{
if(name_arr[x]>=97 && name_arr[x]<122)
{
name_arr[x]=toupper(name_arr[x]);
}
}
}
anyone can help my