关于用C编写的的日记本系统,求大神帮忙
程序代码:
下面是我在论坛里看到的关于用C编写的日记本系统的代码,我觉得这个系统很好!可是运行时,VC报错, #include 文件或目录不存在,我不知道怎么修改,求大神帮忙!谢谢!! #include<stdio.h> #include<stdlib.h> #include<string.h> #include <sys/types.h> #include <dirent.h> #include <sys/stat.h> #define MAXSIZE 1024 #define LENTH 50 typedef struct node{ char date[LENTH]; //yyyy-mm-dd char content[MAXSIZE]; char weather[LENTH]; struct node *next; }dairy; typedef struct user_node{ char dir[LENTH]; char userName[LENTH]; char pwd[LENTH]; struct user_node *next; }userInfo; void prtByKeyWord(dairy *h); void modify_pwd(userInfo *curUser) ; //密码修改 void IU() ; //系统界面设计 void SysLoad() ; //系统启动 void useUI(); //用户功能界面 void regis(); //注册用户 void saveUserInfo(userInfo *H); //永久化保存用户信息 void useSys(userInfo *curUser,int *flag); //使用系统 void prtByDate(dairy *h); void prtOrder(dairy *h); void writeDairy(dairy *h,userInfo *curUser); //写日记 dairy *loadAllDairy(userInfo *curUser); userInfo *getUserInfo(); //获得所有用户账号和密码 userInfo *login(userInfo *H); //登录界面 int trave_dir(char* path,char filename[][LENTH]); //遍历文件夹,获取其中的所有txt文件(一篇日志一个txt文件) int main() { SysLoad(); return 0; } void IU() //系统界面设计 { system("CLS"); printf("\t\t **************** \n"); printf("\t\t ** 欢迎使用 ** \n"); printf("\t\t **************** \n"); printf("\t\t \n"); printf("\t\t \n"); printf("\t\tAuthor:\t\t薛云腾 \n"); printf("\t\tClass:\t\t计算机二班 \n"); printf("\t\tStuPayroll:\t3110307212 \n"); printf("\t\t \n"); printf("\t\t \n"); printf("\t\t====== *** ===小型日记本系统=== *** ======\n"); printf("\t\t== ==\n"); printf("\t\t== ==\n"); printf("\t\t== l/L、用户登录; ==\n"); printf("\t\t== r/R、注册新用户; ==\n"); printf("\t\t== q/Q、退出; ==\n"); printf("\t\t== ==\n"); printf("\t\t=======****************************=======\n\n\n"); printf("您的选择:"); } void SysLoad() //系统启动 { char choose; int flag=1; userInfo *H,*curUser; while(1) { IU(); fflush(stdin); scanf("%c",&choose); getchar(); switch (choose) { case 'l': case 'L': H=getUserInfo(); if(H->next!=NULL) { curUser=login(H); flag=1; if(curUser!=NULL) { while(flag){ useUI(); useSys(curUser,&flag); } } } else printf("尚未有任何用户注册!请先注册...\n\n\n"); printf("\n\n\n"); system("PAUSE"); //按任意键继续 break; case 'r': case 'R': regis(); printf("\n\n\n"); system("PAUSE"); //按任意键继续 break; case 'q': case 'Q': exit(0); default: printf("\n\n输入错误,请重选...\n\n\n"); system("PAUSE"); break; } } } userInfo *login(userInfo *H) //登录界面 { userInfo *p; char userName[LENTH]; char pwd[LENTH]; system("CLS"); printf("请输入用户名:"); scanf("%s",userName); printf("请输入密码:"); scanf("%s",pwd); p=H->next; while(p){ if(strcmp(p->userName,userName)==0){ if(strcmp(p->pwd,pwd)==0) return p; else { printf("\n\n密码错误!返回主菜单...\n\n\n"); return NULL; } } p=p->next; } printf("\n\n该用户名不存在!返回主菜单...\n\n\n"); return NULL; } userInfo *getUserInfo() //获得所有用户账号和密码 { FILE *fp =NULL; userInfo *H=NULL,*p,*r; H=(userInfo *)malloc(sizeof(struct user_node)); H->next=NULL; r=H; if((fp=fopen("userInfo.txt","r"))!=NULL) { while( !(feof(fp)) ) { p=(userInfo *)malloc(sizeof(struct user_node)); fscanf(fp,"%s%s%s",p->userName,p->pwd,p->dir); p->next=r->next; r->next=p; r=p; } } fclose(fp); return H; } void regis() //注册用户 { userInfo *H,*r,*p,*q; char fileDir[LENTH]="md c:\\"; //默认创建路径为c盘 int flag=0; char userName[LENTH]; char pwd[LENTH]; char dir[LENTH]; H=getUserInfo(); while(1) { if(flag!=0) break; system("CLS"); printf("请输入注册的用户名:"); scanf("%s",userName); printf("请输入密码:"); scanf("%s",pwd); printf("请输入您的个人文件夹名:"); scanf("%s",dir); p=H->next; r=H; while(p) { if(strcmp(p->userName,userName)==0) { printf("\n\n该用户名已经存在!请重新输入...\n\n\n"); system("PAUSE"); break; } r=p; p=p->next; } if(p==NULL) flag=1; } q=(userInfo *)malloc(sizeof(struct user_node)); strcpy(q->userName,userName); strcpy(q->pwd,pwd); strcpy(q->dir,dir); q->next=NULL; r->next=q; strcat(fileDir,q->dir); system(fileDir); saveUserInfo(H); printf("\n\n注册成功!\n\n\n"); } void saveUserInfo(userInfo *H) //永久化保存用户信息 { FILE *fp; userInfo *p; if((fp=fopen("userInfo.txt","w"))==NULL) { printf("\n文件打开失败!\n\n"); exit(0); } p=H->next; while(p) { if(p->next==NULL) fprintf(fp,"%s %s %s",p->userName,p->pwd,p->dir); else fprintf(fp,"%s %s %s\n",p->userName,p->pwd,p->dir); p=p->next; } fclose(fp); } void useUI() { system("CLS"); printf("1、创建日志;\n"); printf("2、查阅指定日期的日记;\n"); printf("3、按顺序查阅日记;\n"); printf("4、按关键字查阅;\n"); printf("5、修改密码;\n"); printf("按任意键返回登录界面;\n\n\n"); printf("您的选择:"); } void useSys(userInfo *curUser,int *flag) //使用系统 { char choose; dairy *h,*p; fflush(stdin); scanf("%c",&choose); fflush(stdin); switch (choose) { case '1': system("CLS"); h=loadAllDairy(curUser); writeDairy(h,curUser); break; case '2': system("CLS"); h=loadAllDairy(curUser); prtByDate(h); printf("\n\n\n"); system("PAUSE"); break; case '3': system("CLS"); h=loadAllDairy(curUser); prtOrder(h); printf("\n\n\n"); system("PAUSE"); break; case '4': system("CLS"); h=loadAllDairy(curUser); prtByKeyWord(h); break; case '5': system("CLS"); modify_pwd(curUser); *flag=0; break; default: printf("\n\n您确定要注销,离开本系统?(n/y)"); scanf("%c",&choose); if(choose!='n' && choose!='N') *flag=0; return; } } void writeDairy(dairy *h,userInfo *curUser) //写日记 { dairy *p=NULL,*q; FILE *fp; char path[256]; char n[LENTH],no[LENTH]; char ch; memset(path,0,256); strcpy(path,"c:/"); p=(dairy *)malloc(sizeof(struct node)); p->next=NULL; printf("文件名:"); scanf("%s",no); printf("日记日期(YYYY-MM-dd):"); scanf("%s",p->date); printf("天气:"); scanf("%s",p->weather); getchar(); printf("日记内容:"); gets(p->content); printf("\n\n保存该日记?(y/n):"); fflush(stdin); scanf("%c",&ch); if(ch!='n' && ch!='N') { strcat(path,curUser->dir); //c:/yun 其中yun是dir的一个例子 strcat(path,"/"); //c:/yun/ strcat(path,no); //c:/yun/no strcat(path,".txt"); //c:/yun/no.txt printf(" %s ",path); if((fp=fopen(path,"w"))==NULL) { printf("\n文件打开失败!日志未保存...\n"); exit(0); } fprintf(fp,"Date:%s\tWeather:%s\n",p->date,p->weather); fprintf(fp,"Content:\t%s",p->content); printf("\n\n日记保存成功!\n\n\n"); fclose(fp); } else printf("\n\n日记未保存!\n\n"); system("PAUSE"); system("CLS"); } dairy *loadAllDairy(userInfo *curUser) { int cnt=0,len = 0 ,i =0; dairy *H=NULL,*p,*r; char filename[50][50]; char path[256]="c:/"; FILE *fp; H=(dairy *)malloc(sizeof(struct node)); H->next=NULL; r=H; strcat(path,curUser->dir); len=trave_dir(path,filename); for(i=0;i
[ 本帖最后由 虚拟情缘 于 2013-4-12 08:26 编辑 ]