Nan 的个人资料心理溃疡照片日志列表 工具 帮助

日志


3月10日

公布代码,需要的拿去用

帮别人做的作业,代码不长,冗余度高,而且幼稚,不到500行,不符合软件工程要求,面向过程,字符界面,没有注释,需要的拿去
传说中的白痴同学录,插入,删除,修改,查询,排序,保存,读取,模块划分清楚,随便改改就变成别的了。
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
void newm();
void open();
void ins();
typedef struct SS S;
struct SS
{
 long number;
 char address[50];
 char name[20];
 long zipCode;
 long tel;
 char email[50];
 S *next;
};
int built=0;
S h;
S *p=&h;
S *q;
int check(S *c)
{
 S *qo;
 for(qo=&h;qo!=c;qo=qo->next)
 {
  if(qo->number==c->number)
  {
   system("cls");
   printf("Already have the same IDNumber.\n");
   return (0);
  }
 }
 return (1);
}
void show2(S *c)
{
 printf("ID Number:%d \n",c->number);
 printf("Name:%s \n",c->name);
 printf("Address:%s\n",c->address);
 printf("ZipCode:%d \n",c->zipCode);
 printf("Tel:%d \n",c->tel);
 printf("E-mail:%s\n",c->email);
}
void ins()
{
 int t;
 q =(S *)malloc(sizeof(S));
 p->next=q;
 printf("Please input IDNumber:");
 scanf("%ld",&q->number);
 printf("Please input Name:");
 scanf("%s",q->name);
 printf("Please input Address:");
 scanf("%s",q->address);
 printf("Please input ZipCode:");
 scanf("%ld",&q->zipCode);
 printf("Please input Tel:");
 scanf("%ld",&q->tel);
 printf("Please input E-mail:");
 scanf("%s",q->email);
 t=check(q);
 if(t==0) {free( q);ins();}
 {
  p=q;
  system("cls");
 }
}
void newm()

 char abs;
 int t;
 int n;
    p=&h;
 for(;;)
 {
  q = (S *)malloc(sizeof(S));
  p->next=q;
  printf("Please input IDNumber:");
  scanf("%ld",&q->number);
  printf("Please input Name:");
  scanf("%s",q->name);
  printf("Please input Address:");
  scanf("%s",q->address);
  printf("Please input ZipCode:");
  scanf("%ld",&q->zipCode);
  printf("Please input Tel:");
  scanf("%ld",&q->tel);
  printf("Please input E-mail:");
  scanf("%s",q->email);
  t=check(q);
  if(t==0)
  {
   free((void *) q);
   continue;
  }
  else
  {
   p=q;
   for(n=0;n!=1;)
   {  
    built=1;
    system("cls");
    printf("Continue? Y/N");
    scanf("%c",&abs);
    switch(abs)
    {
    case 'n':{system("cls"); return;}
    case 'N':{system("cls"); return;}
    case 'y':{system("cls"); n=1;}
    case 'Y':{system("cls"); n=1;}
    }
   }
  }
 }
}
void mod()
{
 int num;
 char a;
 int n;
 if(p==&h)
 {
  printf("No record, press any key to return.");
  getch();
  return;
 }
 for(q=&h;q!=p;q=q->next)
  show2(q->next);
 for(;;)
 {
  printf("Please input IDNumber:");
  scanf("%d",&num);
  q=&h;
  while(q!=p)
  {
   if(q->next->number==num)
   {
    printf("a");
    scanf("%s",q->next->name);
    printf("b");
    scanf("%s",q->next->address);
    printf("c");
    scanf("%d",&q->next->zipCode);
    printf("d");
    scanf("%d",&q->next->tel);
    printf("e");
    scanf("%s",q->next->email);
    return;
   }
   q=q->next;
  }
  for(n=0;n!=1;)
  {
   system("cls");
   printf("The student is not exist. y:continue n:back to main menu");
   scanf("%c",&a);
   switch(a)
   {
   case 'n':{system("cls"); return;}
   case 'N':{system("cls"); return;}
   case 'y':{system("cls"); n=1;}
   case 'Y':{system("cls"); n=1;}
   }
  }
 }
}
void del()
{
 int num;
 char a;
 int n;
 if(p==&h)
 {
  printf("No record, press any key to return.");
  getch();
  return;
 }
 for(q=&h;q!=p;q=q->next)
  show2(q->next);
 for(;;)
 {
  printf("Please input IDNumber:");
  scanf("%d",&num);
  q=&h;
  while(q!=p)
  {
   if(q->next->number==num)
   {
    printf("Do you want to delete this student? y: yes n: no");
    scanf("%c",&a);
    if(a=='y')
    {
     if(q->next==p) p=q;
     q->next=q->next->next;
     return;
    }
    else return;
   }
   q=q->next;
  }
  for(n=0;n!=1;)
  {
   system("cls");
   printf("The student is not exist. y:continue n:back to main menu");
   scanf("%c",&a);
   switch(a)
   {
   case 'n':{system("cls"); return;}
   case 'N':{system("cls"); return;}
   case 'y':{system("cls"); n=1;}
   case 'Y':{system("cls"); n=1;}
   }
  }  
 }
}
void sort()
{  
 S *s;
 int tag;
 long min=-1;
 long minp=100000000;
 if(p==&h)
 {
  printf("No record, press any key to return.");
  getch();
  return;
 }
 system("cls"); 
 for(;;)
 {
  tag=0;
  for(q=&h;q!=p;)
  {
   if(q->next->number>min&&q->next->number<minp)
   {
    minp=q->next->number;
    s=q->next;
    tag=1;
   }
   q=q->next;
  }
  if(tag==1)
  {
   show2(s);
   min=minp;
   minp=100000000;
   continue;
  }
  break;
 }
    getch();
}
void ByNumber()
{
 int num;
 int n;
 char a;
 if(p==&h)
 {
  printf("No record, press any key to return.");
  getch();
  return;
 }
 for(;;)
 {
  printf("Please input IDNumber:");
  scanf("%d",&num);
  q=&h;
  while(q!=p)
  {
   if(q->next->number==num)
   {
    show2(q->next);
    getch();
    return;
   }
   q=q->next;
  }
  for(n=0;n!=1;)
  {
   system("cls");
   printf("The student is not exist. y:continue n:back to main menu");
   scanf("%c",&a);
   switch(a)
   {
   case 'n':{system("cls"); return;}
   case 'N':{system("cls"); return;}
   case 'y':{system("cls"); n=1;}
   case 'Y':{system("cls"); n=1;}
   }
  }
 }
}
void ByName()
{
 char name[20];
 char a;
 int n;
 if(p==&h)
 {
  printf("No record, press any key to return.");
  getch();
  return;
 }
 for(;;)
 {
  printf("Please input name:");
  scanf("%s",name);
  q=&h;
  while(q!=p)
  {
   if(!strcmp(q->next->name,name))
   {
    show2(q->next);
    getch();
    return;
   }
   q=q->next;
  }
  for(n=0;n!=1;)
  {
   system("cls");
   printf("The student is not exist. y:continue n:back to main menu");
   scanf("%c",&a);
   switch(a)
   {
   case 'n':{system("cls"); return;}
   case 'N':{system("cls"); return;}
   case 'y':{system("cls"); n=1;}
   case 'Y':{system("cls"); n=1;}
   }
  }
 }
}

void qu()
{
 char input;
 for(;;)
 {
  system("cls");
  printf("|---------------------------------------------| \n");
  printf("|                    Query                    | \n");
  printf("|---------------------------------------------| \n");
  printf("|               0----By IDNumber              | \n");
  printf("|               1----By Name                  | \n");
  printf("|               2----Return                   | \n");
  printf("|---------------------------------------------| \n");
  input=getch(); 
  switch(input)
  {
  case '0':  system("cls"); ByNumber();break;
  case '1': system("cls"); ByName();break;
  case '2':  return;
  }
 }
}
void save()
{
 char *filename;
 FILE *fp;
 filename=malloc(20*sizeof(char)); 
 if(p==&h)
 {
  printf("No record, press any key to return.");
  getch();
  return;
 }
 q=&h;
    printf("Please input the filename:");
 scanf("%s",filename);
 fp=fopen(filename,"w");
 for(q=&h;q!=p;)
 {  
  fwrite(q->next,sizeof(S),1,fp);
  q=q->next;
 }
 fclose(fp);
}
void load()
{
    char *filename;
 FILE *fp;
 filename=malloc(20*sizeof(char));  
 q=&h;
    printf("Please input the filename:");
 scanf("%s",filename);
 if((fp=fopen(filename,"r"))==NULL)
 {
  printf("error");
  getch();
  return;
 }
 for(p=&h;;)
 {  
  fgetc(fp);
  if (feof(fp)) break;      
        fseek(fp,-1L,1);
  q=(S *)malloc(sizeof(S));
  fread(q,sizeof(S),1,fp);
  p->next=q;
  p=q;
 }
 built=1;
 fclose(fp);
}
void open()
{   char start;
 for(;;)
 {
  system("cls");
  printf("|---------------------------------------------|\n");
  printf("|                 MAIN MENU                   |\n");
  printf("|---- ------- --------------------------------|\n");
  printf("|               A----New                      |\n");
  printf("|               B----Insert                   |\n");
  printf("|               C----Modify                   |\n");
  printf("|               D----Delete                   |\n");
  printf("|               E----Sort                     |\n");
  printf("|               F----Query                    |\n");
  printf("|               S----Save                     |\n");
  printf("|               L----Load                     |\n");
  printf("|               Q----Quit                     |\n");
  printf("|---------------------------------------------|\n");
  start=getch();
  if(built==1)
  {
   switch(start)
   {
   case 'a':  system("cls"); newm();break;
   case 'A': system("cls"); newm();break;
   case 'b':  system("cls"); ins();break;
   case 'B': system("cls"); ins();break;
   case 'c':  system("cls"); mod();break;
   case 'C': system("cls"); mod();break;
   case 'd':  system("cls"); del();break;
   case 'D': system("cls"); del();break;
   case 'e':  system("cls"); sort();break;
   case 'E': system("cls"); sort();break;
   case 'f':  system("cls"); qu();break;
   case 'F': system("cls"); qu();break;
   case 's':  system("cls"); save();break;
   case 'S': system("cls"); save();break;
   case 'l':  system("cls"); load();break;
   case 'L': system("cls"); load();break;
   case 'q':  exit(0);
   case 'Q': exit(0);
   }
  }
  else{
   switch(start)
   {
   case 'a':  system("cls"); newm();break;
   case 'A': system("cls"); newm();break;
   case 'l':  system("cls"); load();break;
   case 'L': system("cls"); load();break;
   default: system("cls");printf("Please New or Load first");start=getch();
   }
  }
 }
}
void main()
{
 open();
}
 

评论 (2)

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。

若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


还没有 Windows Live ID 吗?请注册

HE 7贺磊发表:
这还叫不长啊
4 月 11 日
XULi发表:
老弟,很勤奋嘛!
3 月 20 日

引用通告

此日志的引用通告 URL 是:
http://psychicanker.spaces.live.com/blog/cns!4CACFA31DC221B5C!639.trak
引用此项的网络日志