파일처리 관련 질문 입니다.
해솔
질문 제목 : 알고리즘을 잘 모르겠네요 ㅜ질문 요약 :계좌번호, 이름, 잔액이 들어 있는 파일을 불러와서 계좌생성, 입출금, 계좌폐쇠, 내역갱신, 고객조회, 종료
를 하는 프로그램 입니다. 나머지는 다 구현이 되었는데 계좌폐쇠랑 내역갱신을 어찌해야 할지 모르겠네요.
내역갱신은 계좌번호 순서로 대로 오름차순으로 정렬이 되야 하는데요..이두가지 부분좀 도와주세요 ㅜ
질문 내용 :
#includestdio.h
#includestring.h
#includestdlib.h
#define NAME_LEN 20
typedef struct _Account{
int id;
char name[NAME_LEN];
int balance;
struct _Account *next;
}Account;
Account *head, *tail;
void init_Account(FILE *fp);
void MakeAccount(FILE *fp);
void Deposit(FILE *fp);
void WithDraw(FILE *fp);
void WriteAccount(FILE *fp);
void Delete(FILE *fp);
void Inquire(void);
void PrintMenu(void);
void ReadAccount(int, char*, int);
//enum{MAKEACCOUNT=1, DEPOSIT, WITHDRAW, INQUIRE, EXIT};
int main(void)
{
int choice, choice2;
FILE *fp;
fp = fopen(account.txt,r+);
init_Account(fp);
while(1)
{
PrintMenu();
printf(원하시는 서비스를 선택하세요: );
scanf(%d, &choice);
/*switch(choice)
{
case MAKEACCOUNT:
MakeAccount(fp);
break;
case DEPOSIT:
Deposit(fp);
break;
case WITHDRAW:
WithDraw(fp);
break;
case INQUIRE:
Inquire();
break;
case EXIT:
return 0;
default:
printf(잘못된 입력(1~5입력 요망).\n);
}*/
if(choice == 1)
MakeAccount(fp);
else if(choice == 2){
printf(1.입금, 2.출금: );
scanf(%d, &choice2);
if(choice2 == 1)
Deposit(fp);
else if(choice2 == 2)
WithDraw(fp);
else
printf(잘못입력 하셨습니다.);
}
else if(choice == 3)
Delete(fp);
else if(choice == 4)
;
else if(choice == 5)
Inquire();
else if (choice == 6)
return 0;
else
printf(잘못입력 하셨습니다.\n);
}
return 0;
}
void init_Account(FILE *fp)
{
int id;
char name[NAME_LEN];
int balance;
head=(Account *)malloc(sizeof(Account));
tail=(Account *)malloc(sizeof(Account));
head-next=tail;
tail-next=tail;
while (fscanf(fp,%d %s %d, &id, name, &balance) == 3) {
ReadAccount(id, name, balance);
}
}
void PrintMenu(void)
{
printf(============================================================\n);
printf(1.계좌개설 2.입출금 3.계좌폐쇠 4.내역갱신 5.고객조회 6.종 료\n);
printf(============================================================\n);
}
void ReadAccount(int id, char *name, int balance)
{
Account *t;
t=(Account *)malloc(sizeof(Account));
t-id=id;
strcpy(t-name, name);
t-balance=balance;
t-next=head-next;
head-next=t;
}
void MakeAccount(FILE *fp)
{
int id;
char name[NAME_LEN];
int balance;
Account *t;
t=(Account *)malloc(sizeof(Account));
printf(\n------계좌 생성------\n);
printf(계좌번호 : ); scanf(%d, &id);
printf(예 금 주 : ); scanf(%s, name);
printf(입 금 액 : ); scanf(%d, &balance);
t-id=id;
strcpy(t-name, name);
t-balance=balance;
t-next=head-next;
head-next=t;
WriteAccount(fp);
}
void Deposit(FILE *fp)
{
int id;
int money;
Account *t;
printf(계좌번호 : ); scanf(%d, &id);
printf(입 금 액 : ); scanf(%d,&money);
for(t=head-next; t!=tail; t=t-next)
{
if(t-id==id)
{
t-balance+=money;
WriteAccount(fp);
return ;
}
}
printf(없는 계좌번호입니다.\n);
}
void WithDraw(FILE *fp)
{
int id;
int money;
Account *t;
printf(계좌번호 : ); scanf(%d, &id);
printf(출 금 액 : ); scanf(%d, &money);
for(t=head-next; t!=tail; t=t-next)
{
if(t-id==id)
{
if(t-balancemoney)
{
printf(출금액이 잔액을 초과할 수 없습니다.\n);
return ;
}
t-balance-=money;
WriteAccount(fp);
return ;
}
}
printf(없는 계좌번호입니다.\n);
}
void Delete(FILE *fp)
{
int id;
//int money;
Account *t;
printf(계좌번호 : ); scanf(%d, &id);
for(t=head-next; t!=tail; t=t-next)
{
if(t-id==id)
{
t-id = NULL;
//strcpy(t-name, NULL);
t-balance = NULL;
//t-next=head-next;
//head-next=t;
WriteAccount(fp);
return;
}
}
printf(없는 계좌번호입니다.\n);
}
void Inquire(void)
{
Account *t;
for(t=head-next;t!=tail;t=t-next)
{
printf(%d %s %d\n, t-id, t-name, t-balance);
}
}
void WriteAccount(FILE *fp)
{
Account *t;
rewind(fp);
for(bsp;for(t=head-next;t!=tail;t=t-next)
{
fprintf(fp,%d %s %d\n, t-id, t-name, t-balance);
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695766 | 달팽이 배열 어디서 틀렸는지 모르겠습니다ㅠㅠ | 연분홍 | 2025-05-23 |
2695738 | fopen과fclose질문~~ (5) | 희선 | 2025-05-23 |
2695707 | 3의 배수 나타내기. (2) | 수리 | 2025-05-23 |
2695626 | 피보나치수열 과제 때문에 질문 드립니다. (6) | 옆집언니 | 2025-05-22 |
2695595 | 포인트공부중입니다 int형에서 4=1 인가요? (3) | 족장 | 2025-05-22 |
2695567 | 드라이브 고유번호를 가져오는 함수 (2) | 초코맛사탕 | 2025-05-21 |
2695533 | 음수의 산술변환! 질문이요 ㅠㅠ... (4) | 꽃여름 | 2025-05-21 |
2695506 | 구조체 배열 이용 도서목록 출력 프로그램 (1) | 가을귀 | 2025-05-21 |
2695450 | c언어 함수 질문이요.... | 이슬비 | 2025-05-20 |
2695403 | VirtualAlloc함수 및 메모리 질문 | 크리에이터 | 2025-05-20 |
2695355 | c언어 for함수 | 미쿡 | 2025-05-19 |
2695327 | 안녕하세요 제가 이번에 좀 큰 프로그램을.. | 악당 | 2025-05-19 |
2695295 | mutex동기화의 thread기반 채팅 서버소스 질문입니다 | 그루터기 | 2025-05-19 |
2695270 | 질문이요..swap 관한겁니다..ㅠㅠ (3) | 콩알녀 | 2025-05-19 |
2695244 | 노땅초보궁금한게 하나 있는데요..반복문(while문)초보자질문 (6) | 큰꽃늘 | 2025-05-18 |
2695166 | do while 문 어떤것이잘못된건지 모르겠어요 (2) | 아이폰 | 2025-05-18 |
2695122 | 구조체에 대해 물어보고 싶은게 있습니다 ^^^.. (7) | 수련 | 2025-05-17 |
2695091 | txt 파일 입출력 후 2차 배열에 저장하기입니다. (3) | 헛장사 | 2025-05-17 |
2695063 | 수도요금 프로그램좀 짜주세요. | 시내 | 2025-05-17 |
2695033 | 답변좀요ㅠㅠ (1) | 비사벌 | 2025-05-16 |