C語言實現(xiàn)ATM機存取款系統(tǒng)
本文實例為大家分享了C語言實現(xiàn)ATM機存取款系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
利用結(jié)構(gòu)體和構(gòu)造函數(shù)并且采用輸入輸出文件實現(xiàn)ATM機系統(tǒng)。
主要功能有:
利用三種方法查詢、開戶、登陸、菜單、取款、修改密碼、存款、轉(zhuǎn)賬、創(chuàng)建個人信息、輸出、刪除、增加、退出。
是一個功能齊全,完備的ATM機系統(tǒng)。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct per //定義結(jié)構(gòu)體
{
char name[20];
char ID[20];
int money;
char mima[6];
struct per * next;
};
typedef struct person //定義另一結(jié)構(gòu)體
{
struct per kehu;
struct person *next;
}L;
void chaxun(struct per *head); //各個函數(shù)的聲明
void kaihu(struct per *head);
void denglu(struct per *head);
void caidan(struct per *head);
void qukuan(struct per *head);
void xgmm(struct per *head);
void cunkuan(struct per *head);
void zhuanzhang(struct per *head);
void chuangjian(struct person **Phead);
void shuchu(struct person *Phead);
void shanchu(struct person **Phead);
void zengjia(struct person **Phead);
void chaxun1(struct person *Phead);
void chaxun2(struct person *Phead);
void chaxun3(struct person *Phead);
void tuichu();
void menu();
/*主函數(shù)*/
//
void main()
{
char x;
char choose; //choose為定義輸入選擇的變量
int flag=1;
struct person *Phead=NULL; //Phead為定義二層頭指針
struct per *head=NULL; //head為定義一層頭指針
printf("*****************************\n");
printf("**歡迎使用ATM自動取款機系統(tǒng)**\n");
printf("*****************************\n");
printf("——————————————\n");
printf("| 1 開戶 |\n");
printf("——————————————\n");
printf("| 2 登陸 |\n");
printf("——————————————\n");
printf("| 3 前臺客戶信息查詢中心|\n");
printf("——————————————\n");
printf("| 4 請選擇您的需求 |\n");
printf("——————————————\n");
scanf("%s",&x);
system("cls");
switch(x)
{
case '1':system("cls");
kaihu(head); //調(diào)用開戶函數(shù)
break;
case '2':system("cls");
denglu(head); //調(diào)用登陸函數(shù)
break;
case '3':system("cls");
menu(); //調(diào)用后臺菜單函數(shù)
break;
}
while(flag)
{
system("cls");
menu(); //調(diào)用后臺菜單函數(shù)
choose=getchar();
switch(choose)
{
case '1':chuangjian(&Phead);
shuchu(Phead); //調(diào)用后臺輸出函數(shù)
system("pause");
system("cls");
break;
case '2':chaxun1(Phead); //調(diào)用后臺卡號查詢函數(shù)
system("pause");
system("cls");
break;
case '3':chaxun2(Phead); //調(diào)用后臺姓名查詢函數(shù)
system("pause");
system("cls");
break;
case '4':
chaxun3(Phead); //調(diào)用后臺余額查詢函數(shù)
system("pause");
system("cls");
break;
case '5':shanchu(&Phead); //調(diào)用后臺刪除用戶函數(shù)
system("pause");
system("cls");
break;
case '6':
zengjia(&Phead); //調(diào)用后臺增加用戶函數(shù)
system("pause");
system("cls");
break;
case '7':shuchu(Phead); //調(diào)用后臺輸出函數(shù)函數(shù)
system("pause");
system("cls");
break;
case '8':shuchu(Phead);
system("pause");
system("cls");
break;
case '0':flag=0;
printf("The end.\n");
break;
}
}
}
/*開戶函數(shù)*/
void kaihu(struct per *head)
{
head=NULL;
FILE *fp; //定義文件指針
struct per *p1=NULL,*p2=NULL; //p1,p2為定義鏈表指針
p1=(struct per*)malloc(sizeof(struct per)); //開辟內(nèi)存單元
printf("請輸入您的姓名:\n"); //請數(shù)據(jù)輸入鏈表中
scanf("%s",p1->name);
printf("請設(shè)置您的卡號:\n");
scanf("%s",p1->ID);
printf("請設(shè)置您銀行卡密碼:\n");
scanf("%s",p1->mima);
p1->money=0;
p1->next=NULL;
printf("您的個人信息為");
printf("姓名:%s \n卡號:%s \n余額:%4d\n",p1->name,p1->ID,p1->money);
if(NULL==head) //為新用戶開辟內(nèi)存單元
{
head=(struct per *)malloc(sizeof(struct per));
head->next=p1; //進行頭插法,將其作為第一個節(jié)點
}
else //為新增客戶開辟內(nèi)存單元
{
for(p2=head;p2->next!=NULL;p2=p2->next); //進行尾插
p2->next=p1;
}
if((fp=fopen("save.txt","ab+"))==NULL) //打開文件
{
printf("cannot poen file\n");
return;
}
if(fwrite(p1,sizeof(struct per),1,fp)!=1) //將鏈表信息寫入文件中
printf("file write error\n");
fclose(fp);
printf("\n");
printf("恭喜您開戶成功,請登錄\n");
system("pause");
system("cls");
denglu(head);
}
//登陸函數(shù)
/
void denglu(struct per *head)
{
char d[20];
char mima[20];
int i,j;
FILE *fp; //定義文件指針
struct per *p,*q=NULL;
if((fp=fopen("save.txt","rb+"))==NULL) //打開一個二進制文件,為讀方式
{
printf("不能打開文件\n"); //如不能打開,則結(jié)束程序
}
p=(struct per*)malloc(sizeof(struct per)); //申請空間
head=p;
while(!feof(fp)) //循環(huán)讀數(shù)據(jù)直到文件尾結(jié)束
{
if(1!=fread(p,sizeof(struct per),1,fp))
break; //如果沒讀到數(shù)據(jù),跳出循環(huán)
p->next=(struct per *)malloc(sizeof(struct per)); //為下一個結(jié)點申請空間
q=p; //保存當(dāng)前節(jié)點的指針,作為下一結(jié)點的前驅(qū)
p=p->next; //指針后移,新讀入數(shù)據(jù)鏈到當(dāng)前表尾
}
q->next=NULL; //最后一個結(jié)點的后繼指針為空
fclose(fp);
printf(" **********************\n");
printf(" ***歡迎來都建設(shè)銀行***\n");
printf(" **********************\n");
for(j=1;j<4;j++) //限制卡號輸入的次數(shù)的循環(huán)
{
printf("請輸入您的卡號\n");
scanf("%s",d);
for(q=head;q!=NULL;q=q->next) //遍歷鏈表
{
if(strcmp(q->ID,d)!=0) //核對賬號
{
continue; //跳出循環(huán)
}
else
{
for(i=1;i<4;i++) //限制密碼輸入的次數(shù)的循環(huán)
{
printf("\n\n請輸入您的密碼\n");
scanf("%s",mima);
if(strcmp(q->mima,mima)!=0) //核對密碼
{
printf("密碼不正確。請重新輸入密碼\n");
system("pause");
system("cls");
continue; //若密碼不對,跳出循環(huán)
}
else
{
system("cls");
caidan(head); //調(diào)用菜單函數(shù)
}
}
printf("\n\n\n您輸入密碼三次錯誤,謝謝光臨\n");
system("pause");
system("cls");
exit(0);
}
}
printf("\n\n\n您輸入的卡號有誤,請重試\n");
system("pause");
system("cls");
}
printf("您的卡號三次輸入錯誤,謝謝使用\n");
exit(0);
}
//銀行菜單函數(shù)
/
void caidan(struct per *head)
{
head=NULL;
int i; //i為客戶選擇輸入的變量
while(1)
{
printf("請選擇您需要的業(yè)務(wù)\n"); //銀行業(yè)務(wù)菜單
printf("*********************************\n");
printf("** 1 取款 ***** 2 查詢 **\n");
printf("*********************************\n");
printf("** 3 轉(zhuǎn)賬 ***** 4 修改密碼**\n");
printf("*********************************\n");
printf("** 5 存款 ***** 6 退出 **\n");
printf("*********************************\n");
scanf("%d",&i);
if(i<6||i>0)
{
switch(i)
{
case 1:qukuan(head); //調(diào)用銀行取款函數(shù)
system("pause");
system("cls");
break;
case 2:system("cls");
chaxun(head); //調(diào)用銀行查詢函數(shù)
break;
case 3:system("cls");
zhuanzhang(head); //調(diào)用銀行轉(zhuǎn)賬函數(shù)
break;
case 4:system("cls");
xgmm(head); //調(diào)用銀行修改密碼函數(shù)
break;
case 5:system("cls");
cunkuan(head); //調(diào)用銀行存款函數(shù)
break;
case 6:system("cls");
tuichu(); //調(diào)用銀行退出函數(shù)
break;
}
}
else
{
printf("您的輸入有誤\n");
system("pause");
system("cls");
}
}
}
//銀行取款函數(shù)
//
void qukuan(struct per *head)
{
head=NULL; //head為鏈表頭指針
int i;
FILE *fp; //定義文件指針
struct per *p,*q=NULL;
if((fp=fopen("save.txt","rb+"))==NULL) //打開一個二進制文件,為讀方式
{
printf("不能打開文件\n"); //如不能打開,則結(jié)束程序
}
p=(struct per*)malloc(sizeof(struct per)); //申請空間
head=p;
while(!feof(fp)) //循環(huán)讀數(shù)據(jù)直到文件尾結(jié)束
{
if(1!=fread(p,sizeof(struct per),1,fp))
break; //如果沒有讀到數(shù)據(jù),跳出循環(huán)
p->next=(struct per *)malloc(sizeof(struct per)); //為下一個結(jié)點申請空間
q=p; //保存當(dāng)前結(jié)點的指針,作為下一個結(jié)點的前驅(qū)
p=p->next; //指針后移,新讀入數(shù)據(jù)鏈到當(dāng)前表尾
}
q->next=NULL; //最后一個結(jié)點的后繼指針為空
fclose(fp);
system("cls");
printf("************************************\n");
printf("** 1: 100元 ***** 2:200元 **\n");
printf("************************************\n");
printf("** 3: 300元 ***** 4:400元 **\n");
printf("************************************\n");
printf("** 5: 500元 ***** 6:600元 **\n");
printf("************************************\n");
printf("請按要求選擇您要取款的金額\n");
scanf("%d",&i);
if(i>6||i<=0) //限制輸入范圍
{
printf("對不起,您的輸入有誤\n\n");
return;
}
else
{
i=100*i; //對應(yīng)選項乘以一百為取款金額
if(i>q->money)
{
printf("對不起,您的金額不足\n");
system("pause");
system("cls");
caidan(head); //調(diào)用取款機菜單函數(shù)
}
else
{
q->money-=i; //對金額進行處理
if((fp=fopen("save.txt","wb+"))==NULL) //打開文件
{
printf("cannot open file\n");
return;
}
if(fwrite(q,sizeof(struct per),1,fp)!=1) //將修改的信息重新寫入文件
printf("file write error\n");
printf("您已經(jīng)成功取走%d元\n");
q->next=NULL;
fclose(fp); //關(guān)閉文件
}
}
}
//銀行轉(zhuǎn)賬函數(shù)
/
void zhuanzhang(struct per *head)
{
head=NULL;
FILE *fp; //定義文件指針
struct per *p,*q=NULL;
if((fp=fopen("save.txt","rb+"))==NULL) //打開一個二進制文件,為讀方式
{
printf("不能打開文件\n"); //如不能打開,則結(jié)束程序
}
p=(struct per*)malloc(sizeof(struct per)); //申請空間
head=p;
while(!feof(fp)) //循環(huán)讀數(shù)據(jù)直到文件尾結(jié)束
{
if(1!=fread(p,sizeof(struct per),1,fp))
break; //如果沒讀到數(shù)據(jù),跳出循環(huán)
p->next=(struct per *)malloc(sizeof(struct per)); //為下一個結(jié)點申請空間
q=p; //保存當(dāng)前結(jié)點的指針,作為下一個結(jié)點的前驅(qū)
p=p->next; //指針后移,新讀入數(shù)據(jù)鏈到當(dāng)前表尾
}
q->next=NULL; //最后一個結(jié)點的后繼指針為空
fclose(fp);
int i,j,k;
printf("請輸入帳號號碼\n");
scanf("%d",&i);
printf("請再次輸入帳號號碼\n"); //核對卡號
scanf("%d",&j);
if(i!=j)
{
printf("兩次賬號不同,請重新輸入\n");
zhuanzhang(head);
}
else
{
system("cls");
printf("************************************\n");
printf("** 1: 100元 ***** 2:200元 **\n");
printf("************************************\n");
printf("** 3: 300元 ***** 4:400元 **\n");
printf("************************************\n");
printf("** 5: 500元 ***** 6:600元 **\n");
printf("************************************\n");
printf("請輸入轉(zhuǎn)賬金額\n");
scanf("%d",&k);
if(k>6||k<=0)
{
printf("對不起,您的輸入有誤\n\n");
return;
}
else
{
k=k*100;
if(k>q->money) //對余額進行判斷
{
printf("對不起,您的余額不足\n");
system("pause");
system("cls");
caidan(head);
}
else
{
printf("您已成功轉(zhuǎn)賬%d元\n",k);
q->money-=k;
if((fp=fopen("save.txt","wb+"))==NULL)
{
printf("cannot open file\n");
return;
}
if(fwrite(q,sizeof(per),1,fp)!=1) //將數(shù)據(jù)重新寫入文件
printf("file write error\n");
q->next=NULL;
fclose(fp);
system("pause");
system("cls");
}
}
}
}
//銀行查詢函數(shù)
/
void chaxun(struct per *head)
{
head=NULL; //鏈表頭指針
FILE *fp; //定義文件指針
struct per *p,*q=NULL;
if((fp=fopen("save.txt","rb+"))==NULL) //打開一個二進制文件,為讀方式
{
printf("不能打開文件\n"); //如不能打開,則結(jié)束程序
}
p=(struct per*)malloc(sizeof(struct per)); //申請空間
head=p;
while(!feof(fp)) //循環(huán)讀數(shù)據(jù)直到文件尾結(jié)束
{
if(1!=fread(p,sizeof(struct per),1,fp))
break; //如果沒讀到數(shù)據(jù),跳出循環(huán)
p->next=(struct per *)malloc(sizeof(struct per)); //為下一個結(jié)點申請空間
q=p; //保存當(dāng)前結(jié)點的指針,作為下一個結(jié)點的前驅(qū)
p=p->next; //指針后移,新讀入數(shù)據(jù)鏈到當(dāng)前表尾
}
q->next=NULL; //最后一個結(jié)點的后繼指針為空
fclose(fp);
printf("您卡上原有余額%d元\n\n",q->money);
system("pause");
system("cls");
}
//銀行修改密碼函數(shù)
//
void xgmm(struct per *head)
{
head=NULL; //鏈表頭指針
char mima[20];
FILE *fp; //定義文件指針
struct per *p,*q=NULL;
if((fp=fopen("save.txt","rb+"))==NULL) //打開一個二進制文件,為讀方式
{
printf("不能打開文件\n"); //如不能打開,則結(jié)束程序
}
p=(struct per*)malloc(sizeof(struct per)); //申請空間
head=p;
while(!feof(fp)) //循環(huán)讀數(shù)據(jù)直到文件尾結(jié)束
{
if(1!=fread(p,sizeof(struct per),1,fp))
break; //如果沒讀到數(shù)據(jù),跳出循環(huán)
p->next=(struct per *)malloc(sizeof(struct per)); //為下一個結(jié)點申請空間
q=p; //保存當(dāng)前結(jié)點的指針,作為下一個結(jié)點的前驅(qū)
p=p->next; //指針后移,新讀入數(shù)據(jù)鏈到當(dāng)前表尾
}
q->next=NULL; //最后一個結(jié)點的后繼指針為空
fclose(fp);
printf("請輸入您的原密碼\n");
scanf("%s",mima);
if(strcmp(q->mima,mima)==0) //核對密碼
{
{
printf("密碼正確\n");
printf("請輸入您的新密碼:\n");
scanf("%s",q->mima);
if((fp=fopen("save.txt","wb+"))==NULL) //文件頭指針
{
printf("cannot open file\n");
}
if(fwrite(q,sizeof(struct per),1,fp)!=1) //將修改的密碼重新寫入文件
printf("file write error\n");
fclose(fp);
printf("修改密碼成功\n\n\n\n\n");
}
}
else
{
printf("您輸入的密碼與原密碼不同\n");
return;
system("pause");
}
q->next=NULL;
}
//銀行存款函數(shù)
void cunkuan(struct per *head)
{
int i;
head=NULL; //鏈表頭指針
FILE *fp; //定義文件指針
struct per *p,*q=NULL;
if((fp=fopen("save.txt","rb+"))==NULL) //打開一個二進制文件,為讀方式
{
printf("不能打開文件\n"); //如不能打開,則結(jié)束程序
}
p=(struct per*)malloc(sizeof(struct per)); //申請空間
head=p;
while(!feof(fp)) //循環(huán)讀數(shù)據(jù)直到文件尾結(jié)束
{
if(1!=fread(p,sizeof(struct per),1,fp))
break; //如果沒讀到數(shù)據(jù),跳出循環(huán)
p->next=(struct per *)malloc(sizeof(struct per)); //為下一個結(jié)點申請空間
q=p; //保存當(dāng)前結(jié)點的指針,作為下一個結(jié)點的前驅(qū)
p=p->next; //指針后移,新讀入數(shù)據(jù)鏈到當(dāng)前表尾
}
q->next=NULL; //最后一個結(jié)點的后繼指針為空
fclose(fp);
system("cls");
printf("您卡上原有余額%d元\n",q->money);
printf("************************************\n");
printf("** 1: 100元 ***** 2:200元 **\n");
printf("************************************\n");
printf("** 3: 300元 ***** 4:400元 **\n");
printf("************************************\n");
printf("** 5: 500元 ***** 6:600元 **\n");
printf("************************************\n");
printf("請選擇您要存入的余額\n");
scanf("%d",&i);
if(i>6||i<=0)
{
printf("對不起,您的輸入有誤\n\n");
return;
}
else
{
i=100*i;
q->money+=i;
if((fp=fopen("save.txt","wb+"))==NULL) //打開文件
{
printf("cannot open file\n");
}
if(fwrite(q,sizeof(struct per),1,fp)!=1) //將修改的密碼重新寫入文件
printf("file write error\n");
printf("您已經(jīng)成功存取%d元\n",i);
q->next=NULL;
fclose(fp);
system("pause");
system("cls");
}
}
//退出銀行函數(shù)
///
void tuichu()
{
printf("謝謝使用\n");
exit(0);
}
//后臺運行菜單函數(shù)
///
void menu()
{
printf("****************歡迎來到建設(shè)銀行取款機系統(tǒng)****************\n\n\n\n");
printf("**************************************************\n");
printf("**** 1 建立信息并顯示 ****** 2 卡號查詢信息 ****\n");
printf("**************************************************\n");
printf("**** 3 姓名查詢信息 ****** 4 余額查詢信息 ****\n");
printf("**************************************************\n");
printf("**** 5 刪除某卡號信息 ****** 6 增加新的用戶 ****\n");
printf("**************************************************\n");
printf("**** 7 按余額降序輸出 ****** 8 輸出 ****\n");
printf("**************************************************\n");
printf("**** 0 退出 ****** 謝謝光臨 ****\n");
printf("**************************************************\n");
printf("請選擇您需要的業(yè)務(wù)\n\n");
}
//后臺運行創(chuàng)建鏈表函數(shù)
void chuangjian(struct person **Phead) //*(*Phead)為指向結(jié)構(gòu)體指針的地址
{
struct person *p,*t; //定義操作指針
char n[20];
char a[20];
int s;
if(*Phead) *Phead=NULL;
printf("請輸入卡號 姓名 余額 (若要結(jié)束請輸入三個為零)\n");
printf("請輸入卡號\n");
scanf("%s",n);
printf("請輸入姓名\n");
scanf("%s",a);
printf("請輸入預(yù)存金額\n");
scanf("%d",&s);
if(s==0) return;
p=(L *)malloc(sizeof(L)); //將信息輸入鏈表中
strcpy(p->kehu.ID,n);
strcpy(p->kehu.name,a);
*Phead=p; //將指針重新指向頭指針
printf("請輸入卡號\n");
scanf("%s",n);
printf("請輸入姓名\n");
scanf("%s",a);
printf("請輸入預(yù)存金額\n");
scanf("%d",&s);
while(s)
{
t=p; //將p的值賦給t,p又可以儲存下一個結(jié)點
p=(L *)malloc(sizeof(L)); //為新結(jié)點開辟新的內(nèi)存
strcpy(p->kehu.ID,n);
strcpy(p->kehu.name,a);
p->kehu.money=s;
p->next=NULL;
t->next=p; //將p的值接在t(即上一個結(jié)點的后面)
printf("請輸入卡號\n"); //尾插法
scanf("%s",n);
printf("請輸入姓名\n");
scanf("%s",a);
printf("請輸入預(yù)存金額\n");
scanf("%d",&s);
}
}
//后臺運行輸出鏈表函數(shù)
/
void shuchu(struct person *Phead)
{
printf("\n\n");
if(NULL==Phead)
{
printf("沒有客戶信息可輸出!\n"); //若頭指針指向空,則沒有客戶信息
return;
}
while(Phead) //遍歷輸出鏈表中所有客戶信息
{
printf("卡號:%s\n姓名:\n余額:%d\n",Phead->kehu.ID,Phead->kehu.name,Phead->kehu.money);
Phead=Phead->next;
}
printf("\n\n");
}
//后臺運行卡號查詢函數(shù)
///
void chaxun1(struct person*Phead)
{
char m[20]; //定義輸入查找客戶卡號的變量
if(NULL==Phead) //若頭指針向空,則沒有客戶信息
{
printf("沒有客戶信息可查詢!\n");
return;
}
printf("請輸入要查詢的客戶卡號:\n");
scanf("%s",m);
while(NULL!=Phead&&strcmp(Phead->kehu.ID,m)!=0) //在鏈表中遍歷尋找中,直到鏈表存在并且卡號核對無誤
Phead=Phead->next;
if(Phead==NULL) //若指針指最后指向空,則沒有客戶信息
printf("對不起,沒有該用戶!\n");
else
printf("卡號:%s\n姓名:\n余額:%d\n",Phead->kehu.ID,Phead->kehu.name,Phead->kehu.money);
} //若找到,則輸出客戶信息
//后臺運行姓名查詢函數(shù)
/
void chaxun2(struct person *Phead)
{
char m[20]; //定義輸入查找客戶卡號的變量
if(NULL==Phead) //若頭指針向空,則沒有客戶信息
{
printf("沒有客戶信息可查詢!\n");
return;
}
printf("請輸入要查詢的客戶姓名:\n");
scanf("%s",m);
while(NULL!=Phead&&strcmp(Phead->kehu.name,m)!=0) //在鏈表中遍歷尋找中,直到鏈表存在并且姓名核對無誤
Phead=Phead->next;
if(Phead==NULL) //若指針指最后指向空,則沒有客戶信息
printf("對不起,沒有該用戶!\n");
else
printf("卡號:%s\n姓名:\n余額:%d\n",Phead->kehu.ID,Phead->kehu.name,Phead->kehu.money);
} //若找到,則輸出客戶信息
//后臺運行余額查詢函數(shù)
/
void chaxun3(struct person *Phead)
{
long x; //定義輸入查找客戶余額的變量
if(NULL==Phead) //若頭指針向空,則沒有客戶信息
{
printf("沒有客戶信息可查詢!\n");
return;
}
printf("請輸入要查詢的客戶信息的余額:\n");
scanf("%ld",&x);
while(NULL!=Phead&&Phead->kehu.money!=x) //在鏈表中遍歷尋找中,直到鏈表存在并且余額核對無誤,繼續(xù)尋找
Phead=Phead->next;
if(Phead==NULL) //若指針指最后指向空,則沒有客戶信息
printf("對不起,沒有該用戶!\n");
else
printf("該客戶的信息為\n");
printf("卡號:%s\n姓名:\n余額:%d\n",Phead->kehu.ID,Phead->kehu.name,Phead->kehu.money);
} //若找到,則輸出客戶信息
//后臺運行刪除客戶信息函數(shù)
///
void shanchu(struct person **Phead) //*(*Phead)為指向結(jié)構(gòu)體指針的地址
{
char k[20]; //定義輸入查找客戶姓名卡號的變量
struct person *p=*Phead,*t;
if(NULL==(*Phead)) //若指針最后指向空,則沒有客戶信息
{
printf("沒有客戶信息可刪除!\n");
return;
}
printf("請輸入要刪除的客戶卡號:\n");
scanf("%s",k);
if(p->kehu.ID==k) //若第一個客戶就是,則讓頭指針指向下一個結(jié)點
*Phead=(*Phead)->next,free(p);
else
{
while(NULL==p->next&&p->next->kehu.ID!=k) //遍歷尋找,核對客戶卡號
p=p->next; //當(dāng)p->next沒指向空,并且客戶的卡號還沒找到,則繼續(xù)尋找
if(p->next==NULL)
printf("對不起,沒有該客戶!\n");
else
{
t=p->next; //如果找到,則把p->next的值賦給t
p->next=p->next->next;
}
}
}
//后臺運行增加用戶信息函數(shù)
void zengjia(struct person **Phead) //*(*Phead) 為指向結(jié)構(gòu)體指針的地址
{
char n[20]; //定義輸入增加客戶卡號的變量
char a[20]; //定義輸入增加客戶姓名的變量
int s;
L *p,*t,*k; //定義操作指針變量
printf("請輸入要插入的客戶信息\n");
printf("請輸入卡號\n"); //尾插法
scanf("%s",&n);
printf("請輸入姓名\n");
scanf("%s",a);
printf("請輸入預(yù)存金額\n");
scanf("%d",&s);
p=(L *)malloc(sizeof(L)); //開辟空間
strcpy(p->kehu.ID,a); //將新的客戶信息寫入鏈表
p->kehu.money=s;
strcpy(p->kehu.name,n);
if(NULL==(*Phead)) //如果是空鏈表,則把新客戶信息作為第一個結(jié)點
{
*Phead=p; //頭插法
(*Phead)->next=NULL;
return ;
}
else
{
p->next=(*Phead); //頭插法
(*Phead)=p;
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家
相關(guān)文章
C語言數(shù)學(xué)公式來實現(xiàn)土味表白
大家好,本篇文章主要講的是C語言數(shù)學(xué)公式來實現(xiàn)土味表白,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12
C++實現(xiàn)LeetCode(186.翻轉(zhuǎn)字符串中的單詞之二)
這篇文章主要介紹了C++實現(xiàn)LeetCode(186.翻轉(zhuǎn)字符串中的單詞之二),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-08-08

