高手们!帮我在这个程序里添加保存信息到记事本的函数。
#include <stdio.h>#include <conio.h>
#include <alloc.h>
#include <string.h>
struct stu /*通讯录节点结构*/
{ int num;
char sex[3]; /*性别*/
char name[20]; /*姓名*/
char tel[20]; /*电话*/
char addr[31]; /*地址*/
struct stu *next;
};
struct stu *creat(int n)
{
struct stu *head,*p1,*pd;
int i;
for(i=0;i<n;i++)
{
p1=(struct stu*) malloc(sizeof (struct stu));
p1->num=i+1;
printf("No.%d\n",i+1);
printf("Input name\n");
scanf("%s",p1->name);
printf("Input sex \n");
scanf("%s",p1->sex);
printf("Input telephone number\n");
scanf("%s",p1->tel);
printf("Input address\n");
scanf("%s",p1->addr);
if(i==0)
head=pd=p1;
else
pd->next=p1;
pd=p1;
pd->next=0;
}
return head;
}
struct stu *color()
{ struct stu *head;
textbackground(BLUE);
textcolor(YELLOW);
clrscr();
head->next=NULL;
}
void print()
{ struct stu *head;
printf("num\tsex\t\tname\t\ttel.number\t\taddr\n");
while(head!=NULL)
{
printf("%d\t%s\t\t%s\t\t%s\t\t\t%s\n",head->num,head->sex,head->name,head->tel,head->addr);
head=head->next;
}
}
struct stu *del(struct stu *head)
{
struct stu *p,*pf;
int n;
if(head==NULL)
{ printf("no list!"); goto end; }
printf("input number\n");
scanf("%d",&n);
p=head;
while(p->num!=n&&p->next!=NULL)
{ pf=p; p=p->next;}
if(p->num==n)
{
if(p==head) head=head->next;
else pf->next=p->next;
free(p);
}
else
printf("There is no this number!\n");
end: return head;
}
void search()
{ struct stu *head;
char name[20];
int flag=0;
printf("Input name\n");
scanf("%s",name);
while(head!=NULL)
{
if(strcmp(name,head->name)==0)
{flag=1; break;}
else
head=head->next;
}
if(flag==1)
{printf("num\tsex\t\tname\t\ttel.number\t\taddr\n");
printf("%d\t%s\t\t%s\t\t%s\t\t%s\n",head->num,head->sex,head->name,head->tel,head->addr);
}
else
printf("not found!\n");
}
struct stu *add(struct stu *head)
{
struct stu *pnew,*p,*pb;
pnew=(struct stu*) malloc(sizeof (struct stu));
printf("input posision:");
scanf("%d",&pnew->num);
printf("input sex:");
scanf("%s",pnew->sex);
printf("input name:");
scanf("%s",pnew->name);
printf("input telnumber:");
scanf("%s",pnew->tel);
printf("input addr:");
scanf("%s",pnew->addr);
if(head==NULL)
{head=pnew; head->next=NULL;}
else
p=pb=head;
while(p!=NULL)
{ if(p->num==pnew->num)
{pb->next=pnew;
pnew->next=p;
while(p!=NULL)
{p->num=(p->num)+1; p=p->next;}
break;
}
else
if(p->num>pnew->num)
{pb->next=pnew;
pnew->next=p;
break;
}
pb=p;
p=p->next;
}
if(p==NULL)
{pb->next=pnew; pnew->next=NULL;}
return head;
}
void screen()
{
int i;
struct stu *head=NULL;
while(1)
{
printf("\t\tTHE OS OF TXL MANAGER\n");
printf("************************************\n");
printf("press 1.Create the TXL link\n");
printf("press 2.Add the info of the new one\n");
printf("press 3......search\n");
printf("press 4......print\n");
printf("press 5......delete\n");
printf("press 6......exit\n");
printf("************************************\n");
printf("Please choose 1--6:\n");
scanf("%d",&i);
switch(i)
{
case 1 :printf("how many?\n");
scanf("%d",&i);
head=creat(i);
break;
case 2 : head=add(head); break;
case 3 : search(head); break;
case 4 : print(head); break;
case 5 : head=del(head); break;
case 6 : exit(0); break;
}
printf("\nFinished! Press any key...\n");
}
}
main()
{
color();
screen();
search();
getch();}