可以文档读取的钱包,记录自己的消费记录
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
typedef struct date
{char date[15];//时间unsigned int consume;//消费char where[150];//去向
} Data;
typedef struct cost
{Data data;struct cost* next;//下一个结点
} Cost;
Cost *p1=NULL,*p2=NULL,*head=NULL;
unsigned int count=0,money=0,total=0;
int main()
{void add_record();//新增数据void see_record();//查看数据void del_record();//删除数据void rew_record();//修改数据void total_record();//统计数据void output_record();//导出数据void input_record();//导入数据void sort_record();//整理数据void remarks();//寄语void chang_money();int i;FILE *pq;char password[12]={"332428"},input[12];pq=fopen("data.dat","rb");//判断是否早已有了数据if(pq==NULL)pq=fopen("data.dat","wb");fclose(pq);pq=fopen("money.dat","rb");if(pq==NULL)pq=fopen("money.dat","wb");pq=NULL;printf("请输入我的专属密码\n");scanf("%s",input);while(strcmp(password,input)!=0){printf("输入错误,再试试\n");fflush(stdin);getchar();system("cls");printf("请输入我的专属密码\n");scanf("%s",input);}system("cls");printf("\n\t\033[32m恭喜你进入了青哥的高大上记录系统\033[32m\n");printf("\t\033[32m _______ \033[0m\n");printf("\t\033[32m ,--' `--._ \033[32m\n");printf("\t\033[32m ( `-.\033[0m\n");printf("\t\033[32m ,-' _ )\033[0m\n");printf("\t\033[32m / `. , |\033[0m\n");printf("\t\033[32m | -.\_(_ __ |\033[0m\n");printf("\t\033[32m | /\) `----' ( )\033[0m\n");printf("\t\033[32m | / _____ ___| (\033[0m\n");printf("\t\033[32m |,-. \ <_____) (__ ; /\033[0m\n");printf("\t\033[32m |) ) ( (o) (o| (\033[0m\n");printf("\t\033[32m ( | | ) . | ;\033[0m\n");printf("\t\033[32m \ \| ( __) |(\033[0m\n");printf("\t\033[32m ) `--' _____ (__)\033[0m\n");printf("\t\033[32m `-.| `. `---- /\033[0m\n");printf("\t\033[32m |`-._`-. (\033[0m\n");printf("\t\033[32m `- `--^--'\033[0m\n");fflush(stdin);getchar();input_record();while(1){system("cls");fflush(stdin);sort_record();printf("\033[31m SKY消费管理系统\033[0m\n");printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[32m| |\033[0m\n");printf("\033[32m| 1:新增消费记录 |\033[0m\n");printf("\033[32m| 2:查看消费记录 |\033[0m\n");printf("\033[32m| 3:删除已有记录 |\033[0m\n");printf("\033[32m| 4:修改已有记录 |\033[0m\n");printf("\033[32m| 5:统计消费总额 |\033[0m\n");printf("\033[32m| 6:修改补给金额 |\033[0m\n");printf("\033[32m| 7:退出----系统 |\033[0m\n");printf("\033[32m| 共有记录%d条 |\033[0m\n",count);printf("\033[32m| 应该还剩%d元 |\033[0m\n",money-total);printf("\033[32m------------------------------------------------------------\033[0m\n");remarks();printf("\033[33m ╭╯☆★☆★╭╯ \033[0m\n");printf("\033[33m ╰╮★☆★╭╯\033[0m\n");printf("\033[33m │☆╭─╯ \033[0m\n");printf("\033[33m ╭ ╭╯ \033[0m\n");printf("\033[33m ╔╝★╚╗ ★☆╮載滿『幸福』的列車╭☆★ \033[0m\n");printf("\033[33m ║★☆★║ ╔═════╗ ╔═════╗ ╔═════╗ \033[0m\n");printf("\033[33m ║☆★☆║ ║★ ☆║ ║★ ☆║ ║★ ☆║ ║★ ☆║\033[0m\n");printf("\033[33m ◢◎══◎╚═╝◎═◎╝═╚◎═◎╝═╚◎═◎╝═╚◎═◎╝.\033[0m\n");scanf("%d",&i);switch(i){case 1:add_record();break;case 2:see_record();break;case 3:del_record();break;case 4:rew_record();break;case 5:total_record();break;case 6:chang_money();break;case 7:output_record();return;}}
}
void remarks()
{printf("\033[36m世上没有绝望的处境,只有对处境绝望的人。\033[0m\n");printf("\033[36m别想一下造出大海,必须先由小河川开始。\033[0m\n");printf("\033[36m即使爬到最高的山上,一次也只能脚踏实地地迈一步。\033[0m\n");
}void add_record()
{system("cls");fflush(stdin);printf("\033[31m SKY消费管理系统\033[0m\n");printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[31m\"时间格式;2016-12-20\"\033[0m\n");printf("\033[31m\"时间为0则取消添加\"\033[0m\n");p1=(Cost*)malloc(sizeof(Cost));printf("\033[33m消费时间:\033[0m");scanf("%s",p1->data.date);if(strcmp("0",p1->data.date)==0){printf("\033[31m输入无效.\033[0m\n");printf("\033[36m大大O(∩_∩)O请按任意键返回\033[0m\n");getchar();getchar();free(p1);p1=NULL;return;}printf("\033[33m消费数额:\033[0m");scanf("%u",&p1->data.consume);printf("\033[33m消费日记:\033[0m");scanf("%s",p1->data.where);if(count==0){head=p1;p2=p1;p1=NULL;p2->next=NULL;}else{p2->next=p1;p2=p1;p1=NULL;p2->next=NULL;}count++;printf("\033[32m记录成功,fighting!!\033[0m\n");printf("\033[36m大大O(∩_∩)O请按任意键返回\033[0m\n");getchar();getchar();
}void see_record()
{system("cls");printf("\033[31m SKY消费管理系统\033[0m\n");printf("\033[32m--------------------------消费清单--------------------------\033[0m\n");if(count==0)printf("\033[31m\t暂无消费记录哦!\033[0m\n");else{p1=head;while(p1!=NULL){printf("\033[33m日期:%-15s\n金额:%-5u \033[0m\n",p1->data.date,p1->data.consume);printf("\033[33m日记:%s\033[0m\n",p1->data.where);printf("\033[32m------------------------------------------------------------\033[0m\n");p1=p1->next;}}p1=NULL;printf("\033[36m大大O(∩_∩)O请按任意键返回\033[0m\n");getchar();getchar();
}void del_record()
{fflush(stdin);char dele[15];int d,flag=0;Cost *q;system("cls");p1=head;printf("\033[31m SKY消费管理系统\033[0m\n");printf("\033[32m------------------------------------------------------------\033[0m\n");if(p1==NULL){printf("\033[31m暂时没有记录\033[0m\n");system("cls");return;}printf("\033[33m删除哪天的数据呢?\033[0m\n");scanf("%s",dele);while(p1!=NULL){if(strcmp(dele,p1->data.date)==0){printf("\033[33m找到啦!!\033[0m\n");printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[33m日期:%-15s\n金额:%-5u \033[0m\n",p1->data.date,p1->data.consume);printf("\033[33m日记:%s\033[0m\n",p1->data.where);printf("\033[32m------------------------------------------------------------\033[0m\n");flag=1;break;}q=p1;p1=p1->next;}if(flag==1){printf("\033[33m是否真的删除该项数据?\033[0m\n");printf("\033[33m1:确认删除\n2:其他按键取消操作\033[0m\n");scanf("%d",&d);if(d==1&&count>1)//不止一个结点时{if(p1==head)//数据若是第一个数据时{head=head->next;free(p1);p1=NULL;}else if(p1->next==NULL)//若该项为最后一项(不是第一个结点){q->next=NULL;free(p1);p1=NULL;}else//若数据在中间{q->next=p1->next;free(p1);p1=NULL;}count--;printf("\033[33m删除成功\033[0m\n");}else if(d==1&&count==1)//就一个结点时{head=NULL;free(p1);p1=NULL;count--;printf("\033[33m删除成功\033[0m\n");}}elseprintf("\033[31m该日好像没有数据哦!\033[0m\n");printf("\033[36m大大O(∩_∩)O请按任意键返回\033[0m\n");getchar();getchar();
}
void rew_record()
{fflush(stdin);char search[15];int i,flag=0;system("cls");printf("\033[31m SKY消费管理系统\033[0m\n");printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[33m修改哪天的数据呢?\033[0m\n");scanf("%s",search);p1=head;while(p1!=NULL){if(strcmp(search,p1->data.date)==0){printf("\033[33m找到啦!!\033[0m\n");printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[33m日期:%-15s\n金额:%-5u \033[0m\n",p1->data.date,p1->data.consume);printf("\033[33m日记:%s\033[0m\n",p1->data.where);printf("\033[32m------------------------------------------------------------\033[0m\n");flag=1;break;}p1=p1->next;}if(flag==1){printf("\033[33m选择修改哪项数据\033[0m\n");printf("\033[33m1:日期\n2:金额\n3:日记\n4:其他按键取消操作\033[0m\n");scanf("%d",&i);if(i==1)scanf("%s",p1->data.date);else if(i==2)scanf("%u",&p1->data.consume);else if(i==3)scanf("%s",p1->data.where);elsereturn;system("cls");printf("\033[33m修改成功\033[0m\n");printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[33m日期:%-15s\n金额:%-5u \033[0m\n",p1->data.date,p1->data.consume);printf("\033[33m日记:%s\033[0m\n",p1->data.where);printf("\033[32m------------------------------------------------------------\033[0m\n");}elseprintf("\033[31m未匹配到数据\033[0m\n");printf("\033[36m大大O(∩_∩)O请按任意键返回\033[0m\n");getchar();getchar();
}
void total_record()
{fflush(stdin);unsigned int n,total=0;char a[15],b[15];system("cls");printf("\033[31m SKY消费管理系统\033[0m\n");printf("\033[32m------------------------请选择统计区间----------------------\033[0m\n");printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[33m1:统计全部消费金额\033[0m\n");printf("\033[33m2:统计指定间段金额\033[0m\n");printf("\033[33m3:退出统计\033[0m\n");scanf("%d",&n);if(n==1){p1=head;while(p1!=NULL){total+=p1->data.consume;p1=p1->next;}p1=NULL;printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[33m总共消费%d元。\033[0m\n",total);printf("\033[32m------------------------------------------------------------\033[0m\n");}else if(n==2){printf("\033[33m请输入一个时间段(格式 2015-15-10)\n\033[0m");printf("\033[33m起止时间:\033[0m");scanf("%s",a);printf("\033[33m终止时间:\033[0m");scanf("%s",b);p1=head;while(p1!=NULL&&strcmp(b,p1->data.date))p1=p1->next;while(p1!=NULL&&strcmp(a,p1->data.date)){total+=p1->data.consume;p1=p1->next;}if(p1!=NULL)total+=p1->data.consume;p1=NULL;printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[33m%s至%s期间共消费%d元。\033[0m\n",a,b,total);printf("\033[32m------------------------------------------------------------\033[0m\n");}else if(n==3)return;printf("\033[36m大大O(∩_∩)O请按任意键返回\033[0m\n");getchar();getchar();
}void sort_record()
{int i,j;Cost *ago,*p3;Data temp;p2=p1=head;count=0;total=0;while(p1!=NULL){count++;total+=p1->data.consume;p1=p1->next;}while(count>0&&p2->next!=NULL)p2=p2->next;//让p2永远指向链表的尾端if(count==2){if(strcmp(head->data.date,p2->data.date)==-1){temp=head->data;head->data=p2->data;p2->data=temp;}}else if(count>2)for(i=0,p1=head; i<count-1; i++,p1=p1->next){ago=p1;for(j=i+1,p3=p1->next; j<count; j++,p3=p3->next)if(strcmp(ago->data.date,p3->data.date)==-1)ago=p3;if(ago!=p1){temp=ago->data;ago->data=p1->data;p1->data=temp;}}p1=NULL;
}
void output_record()
{FILE *fp,*tp;fp=fopen("data.dat","wb");tp=fopen("money.dat","wb");fwrite(&money,sizeof(unsigned int),1,tp);if(fp==NULL){printf("导出失败。\n");system("cls");return;}p1=head;while(p1!=NULL){fwrite(&p1->data,sizeof(Data),1,fp);p1=p1->next;}fclose(fp);fclose(tp);p1=NULL;printf("\033[31m SKY消费管理系统\033[0m\n");
}
void input_record()
{FILE *fp,*tp;fp=fopen("data.dat","rb");tp=fopen("money.dat","rb");fread(&money,sizeof(unsigned int),1,tp);if(fp==NULL){printf("没能成功导入\n");system("cls");return;}while(!feof(fp)){p1=(Cost*)malloc(sizeof(Cost));if(fread(&p1->data,sizeof(Data),1,fp)==1){if(count==0) head=p2=p1;else{p2->next=p1;p2=p1;}p2->next=NULL;p1=NULL;count++;}else{free(p1);p1=NULL;}}fclose(fp);
}
void chang_money()
{fflush(stdin);int i,change;system("cls");printf("\033[31m SKY消费管理系统\033[0m\n");printf("\033[32m------------------------------------------------------------\033[0m\n");printf("\033[33m1:获得了补给?\033[0m\n");printf("\033[33m2:丢钱了?\033[0m\n");printf("\033[33m3: 其他按键取消操作\033[0m\n");scanf("%d",&i);switch(i){case 1:printf("\033[33m老板得了多少钱?\033[0m\n");scanf("%d",&change);money+=change;break;case 2:printf("\033[33m......掉了多少?\033[0m\n");scanf("%d",&change);money-=change;break;default:return;}printf("\033[36m大大O(∩_∩)O请按任意键返回\033[0m\n");getchar();getchar();
}