?? bwl.cpp
字號:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#include<time.h>
#include<conio.h>
#include<windows.h>
#include<mmsystem.h>
#define NULL 0
#define LEN sizeof(struct bwl)
struct bwl
{
long num;
long num1;
char a[20];
char b[40];
char c[80];
struct bwl *next;
};
int n,i;
long m,j;
void tixing(struct bwl *head)
{
struct bwl *p;
p=head;
do
{
if(j==p->num)
{
PlaySound("今天有事.wav", NULL, SND_FILENAME | SND_ASYNC);
printf("編號:%d\t%-10ld %-10s %-20s %-20s\n",p->num1,p->num,p->a,p->b,p->c);
}
p=p->next;
}
while(p!=NULL);
}
void print(struct bwl *head)
{
struct bwl *p;
i=1;
system("cls");
time_t t;
tm *tp;
t=time(NULL);
tp=localtime(&t);
printf("今日日期:%d年%d月%d日\n",tp->tm_year+1900,tp->tm_mon+1,tp->tm_mday);
printf("*******************************************************************************\n");
p=head;
if(head!=NULL)
do
{
p->num1=i;
printf("編號:%d\t%-10ld %-10s %-20s %-20s\n",p->num1,p->num,p->a,p->b,p->c);
if(m<p->num1)m=p->num1;
p=p->next;
i++;
}
while(p!=NULL);
printf("*******************************************************************************\n");
printf("今天有的事:\n");
tixing(head);
}
struct bwl *creat(void)
{
struct bwl *head;
struct bwl *p1,*p2;
n=0;m=0;
p1=p2=(struct bwl*)malloc(LEN);
printf("請輸入日期,例如:20070226,輸入0結(jié)束\n");
scanf("%ld",&p1->num);
printf("請輸入時(shí)間,例如:下午2點(diǎn)\n");
scanf("%s",&p1->a);
printf("請輸入內(nèi)容摘要,例如:小學(xué)同學(xué)\n");
scanf("%s",&p1->b);
printf("請輸入記錄內(nèi)容,例如:一定去\n");
scanf("%s",&p1->c);
p1->num1=n+1;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct bwl *)malloc(LEN);
printf("請繼續(xù)添加,請輸入日期,例如:20070226,輸入0結(jié)束\n");
scanf("%ld",&p1->num);
if(p1->num==0)break;
printf("請輸入時(shí)間,例如:下午2點(diǎn)\n");
scanf("%s",&p1->a);
printf("請輸入內(nèi)容摘要,例如:小學(xué)同學(xué)\n");
scanf("%s",&p1->b);
printf("請輸入記錄內(nèi)容,例如:一定去\n");
scanf("%s",&p1->c);
p1->num1=n+1;
}
p2->next=NULL;
return head;
}
struct bwl *del(struct bwl *head,long num)
{
struct bwl *p1,*p2;
if(head==NULL) {printf("\nlist null!\n");goto end;}
p1=head;
while(num!=p1->num1&&p1->next!=NULL)
{
p2=p1;p1=p1->next;
}
if(num==p1->num1)
{
if(p1==head)head=p1->next;
else p2->next=p1->next;
printf("delete:%ld\n",num);
n=n-1;
}
else printf("%ld not been found!\n",num);
end:{};
return head;
}
struct bwl *insert(struct bwl *head,struct bwl *stud)
{
struct bwl *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{
head=p0;p0->next=NULL;
}
else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num)
{
if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{
p1->next=p0;p0->next=NULL;
}
}
n=n+1;
return head;
}
void save(struct bwl *head)
{
struct bwl *p;
FILE *fp;
if((fp=fopen("備忘錄.cpp","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
p=head;
while(p!=NULL)
{
if(fwrite(p,LEN,1,fp)!=1)
printf("file write error\n");
p=p->next;
}
fclose(fp);
}
struct bwl *load()
{
struct bwl *head,*p;
FILE *fp;
if((fp=(fopen("備忘錄.cpp","rb")))==NULL)
{
printf("\t\t\t------------------------\n");
printf("\t\t\t the file open error !\n");
printf("\t\t\t------------------------\n");
return NULL;
}
head=NULL;
while((p=(struct bwl *)malloc(LEN))&&(fread(p,LEN,1,fp)==1))
{
p->next=head;
head=p;
}
free(p);
fclose(fp);
return head;
}
struct bwl *sort(struct bwl *head)
{
struct bwl *first,*tail,*p_min,*min,*p;
first=NULL;
while (head!=NULL)
{
for(p=head,min=head;p->next!=NULL;p=p->next)
{
if(p->next->num<min->num)
{
p_min=p;
min=p->next;
}
}
if(first==NULL)
{
first=min;
tail=min;
}
else
{
tail->next = min;
tail=min;
}
if(min==head)
{
head=head->next;
}
else
{
p_min->next=min->next;
}
}
if(first!=NULL)
tail->next=NULL;
head=first;
return head;
}
void windows()
{
printf("\n");
printf("\t┌─────────────────────────────┐\n");
printf("\t│ │\n");
printf("\t│ 歡迎來到備忘錄系統(tǒng)! │\n");
printf("\t│ │\n");
printf("\t│ *** *** ********* *** *** *** │\n");
printf("\t│ *** *** ********* *** *** *** *** │\n");
printf("\t│ *** *** *** *** *** *** *** │\n");
printf("\t│ ********* ********* *** *** *** *** │\n");
printf("\t│ ********* ********* *** *** *** *** │\n");
printf("\t│ *** *** *** *** *** *** *** │\n");
printf("\t│ *** *** ********* ********* ********* *** *** │\n");
printf("\t│ *** *** ********* ********* ********* *** │\n");
printf("\t│ │\n");
printf("\t│ 嚴(yán) 俊 杰 │\n");
printf("\t│ 2006121063 │\n");
printf("\t│ 網(wǎng)絡(luò)(2)班 │\n");
printf("\t│ 網(wǎng) 絡(luò) 工 程 │\n");
printf("\t│ │\n");
printf("\t└─────────────────────────────┘\n");
printf("\t");
getch();
}
void main()
{
time_t t;
tm *tp;
t=time(NULL);
tp=localtime(&t);
printf("今日日期:%d年%d月%d日\n",tp->tm_year+1900,tp->tm_mon+1,tp->tm_mday);
j=(tp->tm_year+1900)*10000+(tp->tm_mon+1)*100+tp->tm_mday;
char x;
m=0;
struct bwl *head,*stu,*p;
long del_num;
p=load();
head=sort(p);
p=head;
windows();
do{
p=load();
head=sort(p);
p=head;
print(p);
printf("\n 1 創(chuàng)建備忘錄請\n");
printf(" 2 刪除指定備忘錄\n");
printf(" 3 添加備忘錄\n");
printf(" 其他輸入退出\n");
x=getch();
if(x=='1')
{
head=creat();
}
else if(x=='2')
{
printf("\n請輸入要?jiǎng)h除指定備忘錄的編號,輸入0結(jié)束:\n");
scanf("%ld",&del_num);
while(del_num!=0)
{
head=del(head,del_num);
print(head);
printf("請輸入要?jiǎng)h除指定備忘錄的編號,輸入0結(jié)束:");
scanf("%ld",&del_num);
}
}
else if(x=='3')
{
stu=(struct bwl *)malloc(LEN);
printf("\n請輸入日期,例如:20070226,輸入0結(jié)束\n");
scanf("%ld",&stu->num);
if(stu->num==0)continue;
printf("請輸入時(shí)間,例如:下午2點(diǎn)\n");
scanf("%s",&stu->a);
printf("請輸入內(nèi)容摘要,例如:小學(xué)同學(xué)\n");
scanf("%s",&stu->b);
printf("請輸入記錄內(nèi)容,例如:一定去\n");
scanf("%s",&stu->c);
m=m+1;
stu->num1=m;
while(stu->num!=0)
{
head=insert(head,stu);
print(head);
stu=(struct bwl *)malloc(LEN);
printf("\n請輸入日期,例如:20070226,輸入0結(jié)束\n");
scanf("%ld",&stu->num);
if(stu->num==0)continue;
printf("請輸入時(shí)間,例如:下午2點(diǎn)\n");
scanf("%s",&stu->a);
printf("請輸入內(nèi)容摘要,例如:小學(xué)同學(xué)\n");
scanf("%s",&stu->b);
printf("請輸入記錄內(nèi)容,例如:一定去\n");
scanf("%s",&stu->c);
m=m+1;
stu->num1=m;
}
}
else exit(0);
save(head);
p=load();
p=sort(p);
}
while(1);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -