标题:高手帮忙修改一下
只看楼主
tang7520
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-9-6
 问题点数:0 回复次数:3 
高手帮忙修改一下
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<string.h>
#include<mem.h>
#include<ctype.h>
#include<alloc.h>
#define LEN sizeof(STUDENT)
typedef struct hj
{
 int age;
 char number[10];
 char name[20],address[50],sex[2];
 struct hj * next;
}STUDENT;
 
int n;
 
int menu_select()
{
 char c;
 
do
{
 system("cls");
 
 printf("********************************************************************************\n");
 printf("\t\t\                Welcome to\n");
 printf("\n\t\t     The student address mange system\n\n");
 printf("**************************************MENU**************************************\n");
 printf("\t\t\t ☆ 1.Input the record.\n");
 printf("\t\t\t ☆ 2.Print all record.\n");
 printf("\t\t\t ☆ 3.Search record on name or number.\n");
 printf("\t\t\t ☆ 4.Search record on address.\n");
 printf("\t\t\t ☆ 5.Delete a record.\n");
 printf("\t\t\t ☆ 6.Insret record to list.\n");
 printf("\t\t\t ☆ 7.Save the file.\n");
 printf("\t\t\t ☆ 8.Quit.\n");
printf("\n\t\t************  Make by zhang zhi guo  ************\n\n");
printf("********************************************************************************\n\n");
printf("\t\t\t Give your choice(0-8):");
c=getchar();}
while(c<'0'||c>'8');
return(c);}
 
STUDENT *creat(void)
{
 STUDENT *head;
 STUDENT *p1,*p2;
 int k=1;
 system("cls");
 head=NULL;
 
 n=0;
 
 p1=p2=(STUDENT *)malloc(LEN);
   if(!p1)
    {printf("\n Out of memory!");
       return(head); }
else{ printf("\nInput the student number:");
 scanf("%s",p1->number);
 printf("\nInput the student age:");
 scanf("%s",&p1->age);
 printf("\nInput the student name:");
 scanf("%s",p1->name);
 printf("\nInput the student address:");
 scanf("%s",p1->address);
 printf("\nInput the student sex:");
 scanf("%s",p1->sex);}
 
while(k==1)
{n=n+1;
 if(n==1) head=p1;
 else p2->next=p1;
      p2=p1;
 p1=(STUDENT *)malloc(LEN);
printf("\nInput the student number:");
 scanf("%s",p1->number);
 printf("\nInput the student age:");
 scanf("%s",&p1->age);
 printf("\nInput the student name:");
 scanf("%s",p1->name);
 printf("\nInput the student address:");
 scanf("%s",p1->address);
 printf("\nInput the student sex:");
 scanf("%s",p1->sex);
 printf("Do you want to input again?(1=yes,0=No)");
 scanf("%d",&k);
}
p2->next=NULL;
return(head);
}
 
 
 STUDENT * print(STUDENT *head)
{
 STUDENT *p;
 system("cls");
 p=head;
 printf("\nNow,these %d record are:\n",n);
 printf("-------------------------------------------------------------------------------\n");
 printf("   Name   |  Number  |  Age  |  Sex  |  Address  \n");
 printf("-------------------------------------------------------------------------------\n");
 if(head!=NULL)
   do{printf("%s   | %s       | %d    | %s    |  %s       \n",p->name,p->number,p->age,p->sex,p->address);
 p=p->next;}
  while(p!=NULL);
printf("*************************************END****************************************");
printf("press any key........");
getch();
return(head);}
 
STUDENT * search(STUDENT *head)
{
 STUDENT *p;
 char s[10];
 system("cls");
 printf("Please enter name or number for searching.\n");
 scanf("%s",s);
 p=head;
if( strcmp(p->name,s)&&(p!=NULL)||( strcmp(p->number,s)&&(p!=NULL) ) )
{p=p->next;
if(p!=NULL)
printf("\n*********************FOUND*********************\n");
printf("   Name   |   Number   |   Age   |   Sex   |   Address   \n");
printf("\n-------------------------------------------------------------\n");
printf("   %s     |  %s        |  %d     |  %s     |  %s           " ,p->name,p->number,p->age,p->sex,p->address  );
printf("\n-------------------------------------------------------------\n");
printf("\n**********************END**********************\n");
}
else printf("There is no record of student on the list.");
printf("press any key......");
getch();
return(head);
}
 
STUDENT * found(STUDENT *head)
{
 STUDENT *p;
 char s[50];
 char a[]="sichuan";
 system("cls");
 printf("Please enter address for searching.\n");
 scanf("%s",s);
 p=head;
if( strcmp(p->address,s)&&(p!=NULL) )
{p=p->next;
if(p!=NULL)
printf("\n*********************FOUND*********************\n");
printf("   Name   |   Number   |   Age   |   Sex   |   Address   \n");
printf("----------------------------------------");
printf(" %s       |  %s        |  %d     | %s      | %s          \n,p->name,p->number,p->age,p->sex,p->address");
printf("---------------------------------------------------");
printf("\n**********************END**********************\n");
}
else printf("There is no record of student on the list.");
return(head);
if( strcmp(p->address,a)==0 )
{printf("this is sichuan student list:\n");
printf("\n*********************FOUND*********************\n");
printf("   Name   |   Number   |   Age   |   Sex   |   Address   \n");
printf("----------------------------------------");
printf(" %s       |  %s        |  %d     | %s      | %s          \n",p->name,p->number,p->age,p->sex,p->address);
printf("---------------------------------------------------");
printf("\n**********************END**********************\n");}
}
 
 
 
STUDENT *delete(STUDENT *head)
{
 STUDENT *p1,*p2;
 char c;
 char s[50];
 system("cls");
 printf("Please rnter the deleted address:");
 scanf("%s",s);
 p1=p2=head;
while(strcmp(p1->address,s)&&(p1!=NULL) )
 {
 p2=p1;
p1=p1->next;}
if(strcmp(p1->address,s)==0)
{
printf("**********FOUND**********\n");
printf("-------------------------------------------------------------\n");
printf("   Name   |   Number   |   Age   |   Sex   |   Address   \n");
printf("-------------------------------------------------------------\n");
printf("   %s     |  %s        |  %d     |  %s     |  %s         \n",p1->name,p1->number,p1->age,p1->sex,p1->address);
printf("\n***************************END*************************");
printf("\nAre you sure delete the student records?");
for(;;)
{scanf("%c",&c);
 if(c=='n'||c=='N') break;
 if(c=='y'||c=='Y')
   {if(p1==head)
      head=p1->next;
   else p2->next=p1->next;}
 n=n-1;
printf("\nAddress %s student have been deleted.\n",s);
printf("\nDon't forget to save.\n");break;
}
 
}
else printf("\nThere is no address %s student on the list.\n",s);
 printf("press any key......");
 getch();
 return(head);
}
 
STUDENT *insert(STUDENT *head,STUDENT *new)
{
 STUDENT *p0,*p1,*p2;
 p1=head;
 p0=new;
printf("\nPlease enter a new record.\n");
printf("Enter the student number:");
scanf("%s",new->number);
printf("Enter the student age:");
scanf("%d",&new->age);
printf("Enter the student name:");
scanf("%s",new->name);
printf("Enter the student address:");
scanf("%s",new->address);
printf("Enter the student sex:");
scanf("%s",new->sex);
if(head==NULL)
 
 {head=p0;
 p0->next=NULL;}
 else
     {p1->next=p0;
p0->next=NULL;}
n=n+1;
printf("\nStudent %s have been inserted.\n",new->number);
printf("Don't forget to save the new file.\n");
return(head);
}
 
void save(STUDENT *head)
{
 FILE *fp;
 STUDENT *p;
 char outfile[10];
 printf("Enter outfile name.for example c:\\address\n");
 scanf("%s",outfile);
 if( (fp=fopen(outfile,"wb") )==NULL )
  {printf("cannot open the file.\n");
   return;}
printf("\nSave the file......\n");
 p=head;
while(p!=NULL)
{fwrite(p,LEN,1,fp);
 p=p->next; }
fclose(fp);
printf("Save the file successfully!\n");
}
main()
{STUDENT *head,new;
 head=NULL;
 for(;;)
 {switch(menu_select() )
{
 case '1': head=creat();break;
 case '2': print(head);break;
 case '3': search(head);break;
 case '4': found(head);break;
 case '5': head=delete(head);break;
 case '6': head=insert(head,&new);break;
 case '7': save(head);break;
 case '8': exit(0);
 
}
}
 
   }
有个错误一直改不了  f:\vc文档\debug\cpp1134.cpp(5) : fatal error C1083: Cannot open include file: 'mem.h': No such file or directory
Error executing cl.exe.

Cpp1134.obj - 1 error(s), 0 warning(s)

帮忙看一下
搜索更多相关主题的帖子: cls Welcome include system number 
2008-09-06 19:22
tang7520
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-9-6
得分:0 
回复 1# tang7520 的帖子
还是不行  改了又是f:\vc文档\debug\cpp182.cpp(7) : fatal error C1083: Cannot open include file: 'alloc.h': No such file or directory
Error executing cl.exe.

Cpp182.obj - 1 error(s), 0 warning(s)
2008-09-07 10:35
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
得分:0 
LS:去掉这个头文件的包含,使用stdlib.h

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-09-07 10:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-231832-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.862436 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved