这个C语言程序为什么会崩溃
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<malloc.h>#include<stdbo...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <stdbool.h>
#include <time.h>
struct Account
{
char password[10];
char card[20];
double money;
struct Account *Next;
};
void jm();
void kaihu();
void xiaohu();
void qukuan();
void cunkuan();
void chaxun();
bool judge();
int people = 0;
int p = 1;
int choice = 0;
int choice2 = 0;
struct Account *pHead = NULL;struct Account *pHead_forever = NULL;
int main(void)
{
pHead = (struct Account*)malloc(sizeof(struct Account));
pHead_forever = pHead;
while(choice!=6)
{
system("cls");
jm();
scanf("%d",&choice);
switch(choice)
{
case 1:
system("cls");
kaihu();
break;
case 2:
system("cls");
xiaohu();
break;
case 3:
system("cls");
qukuan();
break;
case 4:
system("cls");
cunkuan();
break;
case 5:
system("cls");
chaxun();
break;
case 6:
system("cls");
printf("退出系统!");
choice = 6;
break;
}
}
return 0;
}
void jm()
{
printf("***********欢迎使用自助银行************");
printf("\n\n");
printf("1.开户 4.存款\n");
printf("2.销户 5.查询余额\n");
printf("3.取款 6.退出系统\n");
printf("\n");
printf("***************************************");
printf("\n您需要办理的业务是:");
}
void cunkuan()
{
struct Account *p = NULL;
p = pHead_forever;
int i = 0;
system("cls");
printf("请输入账号:");
fflush(stdin);
gets(pHead->card);
if(judge(pHead->card))
{
for(i=0;i<people;++i)
{
if(strcmp(pHead->card,p->card)==0)
break;
p = p->Next;
}
}
else
{
system("cls");
printf("该账户尚未开户,请先开户!");
time_t now = clock();
for(;clock()-now<CLOCKS_PER_SEC;);
return;
}
system("cls");
printf("您想存入的金额为:");
fflush(stdin);
scanf("%lf",p->money);
printf("\n存款成功!");
time_t now = clock();
for(;clock()-now<CLOCKS_PER_SEC;);
return;
}
为什么每次点存款时 当提示输入金额之后 每当我输入完金额之和 程序便会崩溃 提示该内存不能为written。 展开
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <stdbool.h>
#include <time.h>
struct Account
{
char password[10];
char card[20];
double money;
struct Account *Next;
};
void jm();
void kaihu();
void xiaohu();
void qukuan();
void cunkuan();
void chaxun();
bool judge();
int people = 0;
int p = 1;
int choice = 0;
int choice2 = 0;
struct Account *pHead = NULL;struct Account *pHead_forever = NULL;
int main(void)
{
pHead = (struct Account*)malloc(sizeof(struct Account));
pHead_forever = pHead;
while(choice!=6)
{
system("cls");
jm();
scanf("%d",&choice);
switch(choice)
{
case 1:
system("cls");
kaihu();
break;
case 2:
system("cls");
xiaohu();
break;
case 3:
system("cls");
qukuan();
break;
case 4:
system("cls");
cunkuan();
break;
case 5:
system("cls");
chaxun();
break;
case 6:
system("cls");
printf("退出系统!");
choice = 6;
break;
}
}
return 0;
}
void jm()
{
printf("***********欢迎使用自助银行************");
printf("\n\n");
printf("1.开户 4.存款\n");
printf("2.销户 5.查询余额\n");
printf("3.取款 6.退出系统\n");
printf("\n");
printf("***************************************");
printf("\n您需要办理的业务是:");
}
void cunkuan()
{
struct Account *p = NULL;
p = pHead_forever;
int i = 0;
system("cls");
printf("请输入账号:");
fflush(stdin);
gets(pHead->card);
if(judge(pHead->card))
{
for(i=0;i<people;++i)
{
if(strcmp(pHead->card,p->card)==0)
break;
p = p->Next;
}
}
else
{
system("cls");
printf("该账户尚未开户,请先开户!");
time_t now = clock();
for(;clock()-now<CLOCKS_PER_SEC;);
return;
}
system("cls");
printf("您想存入的金额为:");
fflush(stdin);
scanf("%lf",p->money);
printf("\n存款成功!");
time_t now = clock();
for(;clock()-now<CLOCKS_PER_SEC;);
return;
}
为什么每次点存款时 当提示输入金额之后 每当我输入完金额之和 程序便会崩溃 提示该内存不能为written。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询