指导个人日记管理系统(C语言)_第1页
指导个人日记管理系统(C语言)_第2页
指导个人日记管理系统(C语言)_第3页
指导个人日记管理系统(C语言)_第4页
指导个人日记管理系统(C语言)_第5页
已阅读5页,还剩28页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、个人日记管理系统(C语言)# include# include# include# include# include# include/*宏定义ESC和Enter键的ascii值分别是27和13 */#define Esc 27#define Enter 13/*日记结点类型*/ typedef struct diary char date15; /日记日期 char title20; /日记标题 int flag; /用来标记该日记是否满足查阅要求,满足为-1,初始值为0; struct diary *next;DiaryNode; /*用户结点类型 */ typedef struct us

2、er char user_name20; /用户名 char password20; /密码 int count; /存储相应用户的日期篇数 DiaryNode *firstedge; struct user *next; *userList,userNode; /*函数声明*/ void Show_Interface();void Version_file();userList Init_user();void main_meno(userList L); void User_Login(userList L);userList User_apply(userList L);void Hel

3、p_file();void User_Operate(userNode *H,userList L);void Write_dairy(userNode *H,userList L);int Search_dairy(userNode *H,char temp); void Read_dairy(char dairy_name);void Delete_dairy(userNode *H,userList L);void Rejigger_user_password(userNode *H,userList L);void Consult_dairy_meno(userNode *H); vo

4、id Consult_dairy(userNode *H,int i); void Express_chage_dark(char temp);void Dark_chage_express(char temp);void Password_input(char temp);void Save_user(userList L);void Save_dairy(userNode *H);/保存文件 /*/ /*欢迎界面*/void Show_Interface()char xx1080;char res80;int t=10;int i,m,a,b,c;strcpy(xx0,tttPersona

5、l Diary Management Systemn);strcpy(xx1,ttttAlgorithm Design:soulenvyn);strcpy(xx2,ttttCode Editor:soulenvyn);strcpy(xx3,ttttFrame Design:Palon);strcpy(xx4,ttttTest:soulenvy&Palon);strcpy(xx5,ttttVersion 1.0n);strcpy(xx6,ttttPublish:B.S.Pn);strcpy(xx7,ttttJune 8th 2011n);dofor(i=0;i80;i+) printf(*);p

6、rintf(%s,xx0);for(i=0;i=1&a=1&b=1&c0);void Version_file() FILE *fp; char c; system(cls); Sleep(500); fp=fopen(version.txt,r); /以只读的方式打开文件,将文件指针赋给fp if(fp=NULL) printf (n-?- THE FILE CAN NOT BE OPENED.); return ; while(feof(fp)=0) c=fgetc(fp); /将文件中的字符读入 printf(%c,c); Sleep(25); fclose(fp); printf(nn

7、t); system(pause); /*查阅日记操作*/void Consult_dairy(userNode *H,int i) DiaryNode *p; FILE *fp; char temp20; int j; int flag=0; p=H-firstedge; if (i=-1) /进行顺序查询 printf(nn-?- Please input the number of diary:n- ); scanf(%d,&j); if (jcount) while(j1) p=p-next; j-; p-flag=-1; /找到符合条件日记,对应结点的flag赋为-1,以便待会筛选出

8、来 flag=1; else if (i=0) printf(n-?- Please input the time:n- ); /进行日期查询 if (i=15) printf(n-?- Please input the theme:n- ); /进行关键字查询 scanf(%s,temp); rewind(stdin); while(p!=NULL) if(strstr(p-date+i),temp)!=NULL) p-flag=-1; flag=1; /找到符合条件的结点,其flag赋予-1,以便待会筛选出来 p=p-next; if(flag=0) printf(ntt#SORRY,TH

9、E DIARY CAN NOT BE FOUND#); else p=H-firstedge; printf(ntThe diaries are:n); chdir(H-user_name); while(p!=NULL) if(p-flag=-1) printf(ntn); printf(ttName:%sttTime%sn,p-title,p-date); p-flag=0; /筛选输出结点的flag为-1的日记名,日期 Read_dairy(p-title); p=p-next; chdir(.); printf(nntt); system(pause); /*查阅日记菜单*/void

10、Consult_dairy_meno(userNode *H) char choice; printf(nnt |n); printf(t |1.By ordert2.By timet3.By theme tt|n); printf(t |n); printf(n-?- Choose an item(Esc for quit)n- ); choice=getche(); if (choice=Esc) return; switch(choice) case1: Consult_dairy(H,-1);break; case2: Consult_dairy(H,0);break; case3:

11、Consult_dairy(H,15);break; /*删除用户日记操作*/void Delete_dairy(userNode *H,userList L) DiaryNode *p; /指向要删除的结点 DiaryNode *pre; /指向要删除的结点的前驱结点 int i,j; char flag; printf(nn-?- Please input the number to delete:n- ); scanf(%d,&i); rewind(stdin); j=i; p=H-firstedge; while(i1) p=p-next; i-; p-flag=-1; /要删除的结点

12、的flag标识符设为-1 p=H-firstedge; while(p!=NULL&(p-flag=0) pre=p; p=p-next; printf(n-$- You want to delete this diary:n); printf(ttNumber:%dt Name:%stTime:%s,j,p-title,p-date); printf(nDo you want to delete this diary:(Y or N) t); scanf(%c,&flag); rewind(stdin); if(flag=Y|flag=y) if(H-firstedge=p) H-first

13、edge=p-next; /要删除的结点为第一结点时 else pre-next=p-next; /要删除的结点不是第一结点时 else return ; chdir(H-user_name); /把相应用户的目录弄为当前工作目录 H-count-; /用户的日记数减1 remove(p-title); /去掉相应的文件 free(p); /释放要删除的结点空间 Save_dairy(H); /保存用户日记信息,不然原有的用户日记信息还是不变 Save_user(L); /保存用户信息 printf(ntDeleting,please wait.); Sleep(1000); printf(n

14、ntThe diary has delete!nt); system(pause); /*密文转换成明文*/void Dark_chage_express(char temp) int i; i=0; while(tempi!=0) tempi=tempi+2; i=i+1; /*明文转换成密文*/void Express_chage_dark(char temp) int i; i=0; while(tempi!=0) tempi=tempi-2; i=i+1; /*整数输入控制*/int Input_Integer() char str10; long n,i=0; scanf(%s,st

15、r); rewind(stdin); while(stri!=0) /对字符串的各个字符进行判断,只是字符串结束 if(stri9) return -1; i+; n=atoi(str); /利用atoi函数将字符串str转换成整型数 return n; /返回输入的正整数/*初始化用户信息,读取系统已有的用户和用户相应的日记*/userList Init_user() FILE *fp1; FILE *fp2; userList L=NULL; userNode *p; DiaryNode *s; if (fp1=fopen(Userlist,r+)=NULL) return L; whil

16、e(!feof(fp1) p=(userNode *)malloc(sizeof(userNode); if(fread(p,sizeof(userNode),1,fp1)!=1) break; p-firstedge=NULL; /读取系统已有的用户信息 p-next=L; L=p; chdir(p-user_name); /把相应用户目录作为当前工作目录 if(fp2=fopen(dairylist,r+)=NULL) chdir(.); continue; else while(!feof(fp2) s=(DiaryNode *)malloc(sizeof(DiaryNode); /读取

17、系统相应用户的相应日记信息 if(fread(s,sizeof(DiaryNode),1,fp2)!=1) break; s-next=L-firstedge; L-firstedge=s; chdir(.); /把父目录作为当前工作目录 fclose(fp2); fclose(fp1); return(L); /*主菜单*/void main_meno(userList L) char choice;system(cls); do printf(nttPersonal Diary System(v1.0)0) /当不是第一个输入删除键时 ,进行的操作 rewind(stdin); print

18、f(b); printf( ); printf(bb); i-; continue; else if(tempi!=b&i=0) /当不是输入删除键时,输出*号 printf(*); i=i+1; tempi=0; /*读日记操作*/ void Read_dairy(char dairy_name) FILE *fp; char temp200; int i=0; fp=fopen(dairy_name,r); printf(ntThe content of diary is as following:ntt); while(feof(fp)=0) fscanf(fp,%c,&tempi);

19、i+; tempi=0; Dark_chage_express(temp); printf(%sn,temp); fclose(fp);/*修改用户密码*操作*/void Rejigger_user_password(userNode *H,userList L) char temp120; /用于保存原有的密码 ,设计这个有利于密码的更有效率的保存 char temp220; /用于保存第一次输入的密码 char temp320; /用于保存第二次输入的密码 char flag; strcpy(temp1,H-password); Dark_chage_express(temp1); pri

20、ntf(nntYour password is tt%s,temp1); printf(nn-?- Please input the password:n- ); Password_input(temp2); printf(n-?- Please input the password againn- ); Password_input(temp3); while(strcmp(temp2,temp3)!=0) /两二次输入的密码一样 printf(n-!- THE PASSWORDS IS NOT THE SAME!n); printf(nn-?- Please input the passw

21、ord:n- ); Password_input(temp2); printf(n-?- Please input the password againn- ); Password_input(temp3); Express_chage_dark(temp2); strcpy(H-password,temp2); printf(nnttPassword modifying ,please wait.); Sleep(1); Save_user(L); /系统休眠5秒 printf(nntt#Password has been changed!#nnt); system(pause); /*保存

22、相应用户日记信息*/void Save_dairy(userNode *H) FILE *fp; DiaryNode *p; chdir(H-user_name); if(fp=fopen(dairylist,w)=NULL) printf(-!- CAN NOT OPEN THE FILE!n); system(PAUSE); return; p=H-firstedge; while(p!=NULL) fwrite(p,sizeof(DiaryNode),1,fp); p=p-next; chdir(.); fclose(fp); /*保存全部用户信息*/void Save_user(use

23、rList L) FILE *fp; userNode *p; fp=fopen(Userlist,w); p=L; while(p!=NULL) fwrite(p,sizeof(userNode),1,fp); p=p-next; fclose(fp); /*查找是否有同名日记操作*/int Search_dairy(userNode *H,char temp) DiaryNode *p; p=H-firstedge; while(p!=NULL&strcmp(p-title,temp)!=0) p=p-next; if(p!=NULL) return 0; else return 1; /

24、*申请新用户操作*/userList User_apply(userList L) char temp120; char temp220; int i; char flag; userNode *p; userNode *s; rewind(stdin); s=(userNode *)malloc(sizeof(userNode); system(cls); printf(nttt|n); printf(ttt|tRegistert|n); printf(ttt|n); printf(ntUser list:n); p=L; while(p!=NULL) printf(ttt%sn,p-use

25、r_name); p=p-next; /输出系统已存在的用户名,以让用户申请新用户时,有个注意,不申请重复的用户名 p=L; printf(nn-?- Please input a new name:n- ); scanf(%s,s-user_name); rewind(stdin); while(p!=NULL&strcmp(p-user_name,s-user_name)!=0) p=p-next; /判断有没有重复的用户名 while(p!=NULL) printf(n-!- THE NAME IS EXIST!n); printf(n-?- Continue to register?(

26、Y or N)n- ); scanf(%c,&flag); if (flag=N|flag=n)free(s); return L; printf(n-?- Please input the name:n- ); scanf(%s,s-user_name); rewind(stdin); p=L; while(p!=NULL&strcmp(p-user_name,s-user_name)!=0) p=p-next; printf(nttt#The name can be used.#n); printf(n-?- Please input the password:n- ); Password

27、_input(temp1); printf(n-?- Please input the password again:n- ); Password_input(temp2); while(strcmp(temp1,temp2)!=0) printf(n-!- THE PASSWORDS IS NOT THE SAME!n); printf(n-?- Please input the password:n- ); Password_input(temp1); printf(n-?- Please input the password again:n- ); Password_input(temp

28、2); strcpy(s-password,temp1); s-firstedge=NULL; s-count=0; /申请好用户,进行相应的操作 mkdir(s-user_name); /生成相应用户对应的文件夹,文件夹里用来存储相应用户的相应日记 Express_chage_dark(s-password); /进行密码家秘密 s-next=L; L=s; Save_user(L); /每添加一个用户时,都要进行存储用户信息的保存 printf(nttRegistering please wait.); Sleep(2000); printf(nntt#Congratulations on

29、 your application is successful#nnt); system(pause); return(L); /*相应用户登录后的操作*/void User_Operate(userNode *H,userList L) char choice; DiaryNode *p; int i; system(cls); do printf(tt %s ,Welcome to the systemuser_name); printf(t|n); printf(t| 1.New 2.View 3.Delete 4.Modify password t|n); printf(t|n); p

30、rintf(ntDiary list:n); p=H-firstedge; printf(ntt|n); printf(tt|tNO.t themettimet |n); p=H-firstedge; i=1; while(p!=NULL) printf(tt|t%dt %st%st|n,i,p-title,p-date); p=p-next; /输出相应用户的日记名 i+; printf(tt|n); printf(nn-?- Please choose an item(Esc for qiut):n- ); choice=getche(); if (choice=Esc) return;

31、switch(choice) case 1: Write_dairy(H,L);break; /写日记 case 2: Consult_dairy_meno(H);break; /查阅日记 case 3: Delete_dairy(H,L);break; /删除日记 case 4: Rejigger_user_password(H,L);break; /修改用户 system(cls); while(1); /*用户登录操作*/void User_Login(userList L) char temp20; char flag; int i,j,count; userNode *p; Diar

32、yNode *s; p=L; system(cls); printf(nttt|n); printf(ttt|tLogintt|n); printf(ttt|n); printf(ntUser list:n); printf(tt|n); printf(tt|tNO.t namett|n); count=1; while(p!=NULL) printf(tt|t%dt %stt|n,count,p-user_name); p=p-next; count+; /显示系统全部的用户信息,供用户选择登入 printf(tt|n); count-; printf(nn-?- Choose a numb

33、er:n- ); i=Input_Integer(); while(icount|i=-1) printf(nn-!- IUPUT ERROR); printf(n-?- continue to login?(Y or N)n- ); scanf(%c,&flag); if(flag=N|flag=n) return; printf(nn-?- choose a number:n- ); scanf(%d,&i); j=1; p=L; while(jnext; printf(n-$- You has choosen:tt%s,p-user_name); printf(n-?- Iuput th

34、e password:n- ); Password_input(temp); /输入密码 Express_chage_dark(temp); /明码转化为暗码,以跟以保存的用户密码比较 while(strcmp(p-password,temp)!=0) printf(n-!- WRONG PASSWORD!n); printf(n-?- Continue to input?(Y or N)n- ); scanf(%c,&flag); if (flag=N|flag=n) return; printf(n-?- Input the password:n- ); Password_input(temp); Express_chage_dark(temp); printf(nntttLogining please wait.); Sleep(2000); system(cls); User_Operate(p,L); /用户登入后,进行用户操作 /*写日记操作*/ void Write_dairy(userNode *H,userList L) char choi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论