| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 546 人关注过本帖
标题:请看看这是哪里错了啊
只看楼主 加入收藏
qq384200403
Rank: 2
等 级:论坛游民
帖 子:35
专家分:39
注 册:2013-3-1
结帖率:87.5%
收藏
 问题点数:0 回复次数:2 
请看看这是哪里错了啊
   将学生档案信息存放在顺序表List []中,实现学生档案信息顺序表的基本操作,包括:初始化顺序表,在表中插入元素、删除元素。
   基本要求:
初始化顺序表;
程序具有顺序表插入、删除和显示功能,可根据用户需要连续操作(插入、删除位置及要插入元素数值均从键盘输入);
任一操作结束后将顺序表中的内容输出;
程序能检测并提示发生上溢或下溢错误。
可由用户选择退出程序。

这是我写的程序 这是哪里错了啊?



#include<stdio.h>
#define MAXLEN 50  
#include <malloc.h>

typedef struct
{    char  name[30];      
    int   number;     
    char  sex[3];        
    char  nativeplace[50];  
   
  } datatype;
typedef struct
{
    datatype List[MAXLEN];   
    int  size;      
} Seqlist;
Seqlist  *L;
   

 void  initiq(Seqlist *la,int n )
 {   
      int i;
   
     L=(Seqlist*)malloc(sizeof(Seqlist)*n);//为L创建内存
    for(i=0;i<n;i++)
    {
        printf("请输入第%d个学生 姓名 学号 性别 籍贯 \n",i+1);
        scanf("%s%d%s%s",L->List[i].name,&L->List[i].number,L->List[i].sex,L->List[i].nativeplace);
    }
    for(i=0;i<L->size-1;i++)
         printf("%s%d%s%s",L->List[i].name,L->List[i].number,L->List[i].sex,L->List[i].nativeplace);
   
}

int   insertq(Seqlist *la, int i ,datatype e)
{   
    int j;
    if(L->size>=MAXLEN)
     {
        printf("ERROR");
       return 0;
    }
    if (i <1 || i >L->size+1)
    {
        printf("ERROR");
          return 0;
    }
   for (j=L->size-1;j>=j-1;j--)
       L->List[ j+1]=L->List[ j ];
        L->List[ i -1]=e;
        L->size++;
         return 1;
  for (j=0;j<L->size-1;j++)
      printf("%s%d%s%s",L->List[i].name,L->List[i].number,L->List[i].sex,L->List[i].nativeplace);

}
 int   deleteq(Seqlist *la,int  i, datatype  *y )
{
    int  j;
    if(L->size<=0)
    {
        printf("ERROR");
        return 0;
    }
    else if (i <1 || i >L->size)
    {
        printf("ERROR");
       return 0;
    }
    else
    {
          *y=L->List[i-1];
     for ( j=i; j<=L->size-1;j ++)
          L->List[ j -1]=L->List[ j ];
          L->size--;
          for (j=0;j<L->size-1;j++)
      printf("%s%d%s%s",L->List[i].name,L->List[i].number,L->List[i].sex,L->List[i].nativeplace);


         return 1; }
}

        void main ()
{

     int n,m,k; char ch;
    printf("输入学生个数");
    scanf("%d",&n);
      initiq( L, n );
  printf("input 1(插入学生信息)or 0(删除学生信息)");
    scanf("%d",&m);
    while (1)
    {
        if(m==1)
    {
        printf("输入插入元素的位置");
        scanf("%d",&k);
        datatype e;
        printf("输入插入学生的姓名 学号 性别 籍贯 ");
        scanf("%s%d%s%s",e.name,&e.number,e.sex,e.nativeplace);


    insertq(Seqlist *L, int k ,datatype e);
    }
    else
    {
      printf("输入删除元素的位置");
      scanf("%d",&k);
     int   deleteq(Seqlist *L,int  k, datatype  *y );
    }
     printf("\n是否继续? (y/n):");
     scanf("%s",&ch);
     if(ch=='Y'||'y') continue;
     else break;
    }
}
搜索更多相关主题的帖子: include 用户 
2013-03-21 21:32
cherish——
Rank: 1
等 级:新手上路
帖 子:25
专家分:1
注 册:2012-8-18
收藏
得分:0 

int    insertq(Seqlist *L, int k ,datatype e);
    }
    else
    {
      printf("输入删除元素的位置");
      scanf("%d",&k);
     int   deleteq(Seqlist *L,int  k, datatype  *y );
    }
     printf("\n是否继续? (y/n):");
     scanf("%s",&ch);
     if(ch=='Y'||'y') continue;
     else break;
    }
}
     除了这少了int    也不知道哪有问题了   

                        求具体的
2013-03-25 19:02
飞黄腾达
Rank: 2
等 级:论坛游民
帖 子:46
专家分:27
注 册:2013-3-14
收藏
得分:0 
#include<stdio.h>
#define MAXLEN 50  
#include <malloc.h>

typedef struct
{   
char  name[30];      
int   number;     
char  sex[3];        
char  nativeplace[50];  

} datatype;
typedef struct
{
    datatype List[MAXLEN];   
    int  size;      
} Seqlist;



void  initiq(Seqlist *la,int n )
{   
    int i;
   
   
    for(i=0;i<n;i++)
    {
        printf("请输入第%d个学生 姓名 学号 性别 籍贯 \n",i+1);
        scanf("%s%d%s%s",la->List[i].name,&la->List[i].number,la->List[i].sex,la->List[i].nativeplace);
    }
    for(i=0;i<la->size-1;i++)
        printf("%s%d%s%s",la->List[i].name,la->List[i].number,la->List[i].sex,la->List[i].nativeplace);
   
}

void insertq(Seqlist *la, int i ,datatype e)
{   
    int j;
    if(la->size>=MAXLEN)
    {
        printf("ERROR");
        
    }
    if (i <1 || i >la->size+1)
    {
        printf("ERROR");
        
    }
    for (j=la->size-1;j>=j-1;j--)
        la->List[ j+1]=la->List[ j ];
    la->List[i-1]=e;
    la->size++;

    for (j=0;j<la->size-1;j++)
        printf("%s%d%s%s",la->List[i].name,la->List[i].number,la->List[i].sex,la->List[i].nativeplace);
   
}
void deleteq(Seqlist *la,int  i)
{
    int  j;
    if(la->size<=0)
    {
        printf("ERROR");
        
    }
    else if (i <1 || i >la->size)
    {
        printf("ERROR");
   
    }
    else
    {
        
        for ( j=i; j<=la->size-1;j ++)
            la->List[j-1]=la->List[j];
        la->size--;
        for (j=0;j<la->size-1;j++)
            printf("%s%d%s%s",la->List[i].name,la->List[i].number,la->List[i].sex,la->List[i].nativeplace);
        
        
    }
}

void main ()
{
   
    int n,m,k;
    char ch;
    Seqlist *L;
    datatype *e;
    e=(datatype*)malloc(sizeof(datatype));//要为它开辟空间呦
    L=(Seqlist*)malloc(sizeof(Seqlist));//为L创建内存
    printf("输入学生个数");
    scanf("%d",&n);
    initiq( L, n );
    printf("input 1(插入学生信息)or 0(删除学生信息)");
    scanf("%d",&m);
    while (1)
    {
        if(m==1)
        {
            printf("输入插入元素的位置");
            scanf("%d",&k);
            
            printf("输入插入学生的姓名 学号 性别 籍贯 ");
            scanf("%s%d%s%s",e->name,&e->number,e->sex,e->nativeplace);
            
            
            insertq(L,k,*e);//实参不需要定义
        }
        else
        {
            printf("输入删除元素的位置");
            scanf("%d",&k);
            deleteq(L,k);
        }
        printf("\n是否继续? (y/n):");
        scanf("%c",&ch);
        if(ch=='Y'||'y') continue;
        else break;
    }
}
2013-03-25 21:29
快速回复:请看看这是哪里错了啊
数据加载中...
 
   



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

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