标题:为什么输入完数据就开始不停得循环了?
只看楼主
巴斯和凯特
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-9-9
 问题点数:0 回复次数:2 
为什么输入完数据就开始不停得循环了?
#include<string.h>
#include<stdio.h>
#include<malloc.h>
#define LIST_INIT_SIZE   100
#define LISTINCREMENT    10
#define MAXSIZE 100
 typedef struct workers
{    char name[15];//姓名  
char  department[18];//单位
char gender;//性别      
unsigned int age;//年龄     
unsigned long telephone;//电话      
unsigned long wage;//工资
unsigned long num;//职工号   
struct workers *next;
 }DataType;
 
 
 typedef struct
 {
     DataType wok[MAXSIZE];
     int length;

 }sequenlist;
 int menu_select ()
 {
  int k;
  printf("\n          员工管理系统\n");
  printf("******************************************\n ");
  printf("************1.员工信息表建立**************\n ");
  printf("************2.插入员工信息****************\n ");
  printf("************3.修改员工信息****************\n ");
  printf("************4.查询员工信息****************\n ");
  printf("************5.员工信息排序****************\n ");
  printf("************6.员工信息删除****************\n ");
  printf("************0.退出************************\n ");
  printf("------------------------------------------\n ");
  printf("请选择0-5:\n");
  for(;;)
  {
  scanf("%d",&k);

  
  if(k<0||k>5)
     printf("选择错误,重选1-5\n");
  else
    break;
  }
  return k;
 
  
 }// 菜单

  void CreateList (sequenlist *L)
  {
      int i;
      int n;
      printf("请输入员工数量");
      fflush(stdin);
      scanf("%d",&n);
      printf("请输入这%d位员工的信息\n",n);
      printf("----------------------------------------\n");
      for(i=1;i<=n;i++)
      { printf("第%d个职工:",i);
        printf("\n姓名 单位 性别 年龄 电话 工资 职工号  \n");
   
        scanf("%c%c%c%d%s%d%s",&L->wok[i].name,&L->wok[i].department,&L->wok[i].gender,&L->wok[i].age,&L->wok[i].telephone,&L->wok[i].wage,&L->wok[i].num);
        printf("***************************************\n");
   
       }
      
      L->length=n;
      
  }// 表的建立
  int FindListbynum  (sequenlist *L)
  {   int i=0;
      char name[15];
      printf("请输入要查询职工的姓名\n");
      scanf("%s,name");
      for(i=0;i<=L->length;i++)
      {
          if(strcmp(L->wok[i].name,name)==0)
              return i;
      }
    return -1;
  }
void del(sequenlist *L)
{
    int i,j;
    i=FindListbynum  (L);
    if(i==-1)
    {printf("信息输入有误\n");
        return;
    }
    for(j=i;j<=L->length;j++)
    {
        L->wok[j].age=    L->wok[j+1].age;

   
    }
}















int main ()
  {
      sequenlist *L;
      DataType *workers;
      int i;
      L=(sequenlist*)malloc(LIST_INIT_SIZE*sizeof(sequenlist));
      while (1)
      {
          switch (menu_select())
          {case 1:
              printf("********************************\n");
              printf("********职工线性表的建立********\n");
              printf("********************************\n");
              CreateList (L);
              break;
          case 4:
               printf("********************************\n");
               printf("**********职工信息查找**********\n");
               printf("********************************\n");
               FindListbynum  (L);
              break;
          case 0:
          printf("再见!\n");
          }

      
      }
      return 0;
  }
搜索更多相关主题的帖子: department telephone include 电话 姓名 
2015-09-09 11:31
jklqwe111
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:35
帖 子:335
专家分:1125
注 册:2014-4-13
得分:0 
int main ()
  {
      sequenlist *L;
      DataType *workers;
      int i;
      L=(sequenlist*)malloc(LIST_INIT_SIZE*sizeof(sequenlist));
      while (1)
      {
          switch (menu_select())
          {case 1:
              printf("********************************\n");
              printf("********职工线性表的建立********\n");
              printf("********************************\n");
              CreateList (L);
              break;
          case 4:
               printf("********************************\n");
               printf("**********职工信息查找**********\n");
               printf("********************************\n");
               FindListbynum  (L);
              break;
          case 0:
          printf("再见!\n");
           return 0; //跳出函数
          }

      
      }
     
  }

在switch中所有break;语句只能跳出switch这一层,while (1)循环没有出口.
2015-09-09 12:14
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2276
专家分:10647
注 册:2015-3-19
得分:0 
程序代码:
 bool f=true;
        while (!f)
      {
          switch (menu_select())
          {case 1:
              printf("********************************\n");
              printf("********职工线性表的建立********\n");
              printf("********************************\n");
              CreateList (L);
              f=false;
              break;
          case 4:
               printf("********************************\n");
               printf("**********职工信息查找**********\n");
               printf("********************************\n");
               FindListbynum  (L);
               f=false;
              break;
          case 0:
          printf("再见!\n");
           return 0; //跳出函数
          }

      
      }

剑栈风樯各苦辛,别时冰雪到时春
2015-09-09 12:46



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




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

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