| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 344 人关注过本帖
标题:求解,为什么会运行错误??
只看楼主 加入收藏
alonewaiting
Rank: 1
来 自:四川
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-12-4
结帖率:33.33%
收藏
已结贴  问题点数:5 回复次数:2 
求解,为什么会运行错误??

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
#define R 10
typedef struct
 {

     char name[10];
     char sex[4];
     char age[4];
     char Tel[14];
     char qins[5];
     char cla[14];
 }IM;
  IM st[R]={{"r","m","18","15200860466","225","0901"}};

int search(IM q,int n,IM *st)//找出要删去的信息是否存在
{
   int i=0;
   IM *p;
   p=st;
   while(n!=0)
   {
      if(strcmp(q.name,p->name)==0)
      {
         return i;
         break;
      }
      i++;
      p++;
      n--;
   }

  if(n==0&&i!=0)
  {
     printf("there is not a student.\n");
     return -1;
  }
}

void con(int i,int n,IM *st)//删去信息
{
   for(;i<n;i++)
   {
     
      strcpy((st+i)->name,(st+i+1)->name);
      strcpy((st+i)->age,(st+i+1)->age);
      strcpy((st+i)->sex,(st+i+1)->sex);
      strcpy((st+i)->Tel,(st+i+1)->Tel);
      strcpy((st+i)->cla,(st+i+1)->cla);
      strcpy((st+i)->qins,(st+i+1)->qins);
      
     
}
}

void main()
{



int search(IM q,int n,IM *st);
void con(int i,int n,IM *st);

int n=4;


//删去信息过程

   int i,b=1;
   while(b==1)
   {
      IM q;
      
     system("cls");
    printf("********************************************************************************\n\n\n");
    printf("\t\t\t               删除界面\t\t\t\n\n");
    printf("\t\t\t|-----------------------------------|\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t| 请输入要删除的姓名:              |\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t|   Tips:                          |\n");
    printf("\t\t\t|          一旦删除,就不能恢复!   |\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t|-----------------------------------|\n");
    gotoxy(46, 10);
      scanf("%s",&q.name);
      i=search(q,n,st);
      if(i!=-1)
      {
         con(i,n,st);
      
         n--;
      }
      printf("\n 如果你想继续删除,请输入 1,否则请输入 2\n");
      scanf("%d",&b);
   }
  

}




搜索更多相关主题的帖子: search 
2010-12-25 22:11
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:3 
不知道

                                         
===========深入<----------------->浅出============
2010-12-25 22:13
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:3 
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
#define R 10
typedef struct
{

     char name[10];
     char sex[4];
     char age[4];
     char Tel[14];
     char qins[5];
     char cla[14];
}IM;
  IM st[R]={{"r","m","18","15200860466","225","0901"}};

int search(IM q,int n,IM *st)//找出要删去的信息是否存在
{
   int i=0;
   IM *p;
   p=st;
   while(n!=0)
   {
      if(strcmp(q.name,p->name)==0)
      {
         return i;
         break;
      }
      i++;
      p++;
      n--;
   }

  if(n==0&&i!=0)
  {
     printf("there is not a student.\n");
     return -1;
  }
}

void con(int i,int n,IM *st)//删去信息
{
   for(;i<n-1;i++) //不要越界了,因为后面的st+i+1
   {
     
      strcpy((st+i)->name,(st+i+1)->name);
      strcpy((st+i)->age,(st+i+1)->age);
      strcpy((st+i)->sex,(st+i+1)->sex);
      strcpy((st+i)->Tel,(st+i+1)->Tel);
      strcpy((st+i)->cla,(st+i+1)->cla);
      strcpy((st+i)->qins,(st+i+1)->qins);
      
     
}
}

void main()
{



int search(IM q,int n,IM *st);  //不要声明吧
void con(int i,int n,IM *st);

loop: int n=4;


//删去信息过程

   int i,b=1;
   while(b==1)
   {
      IM q;
      
     system("cls");
    printf("********************************************************************************\n\n\n");
    printf("\t\t\t               删除界面\t\t\t\n\n");
    printf("\t\t\t|-----------------------------------|\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t| 请输入要删除的姓名:              |\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t|   Tips:                          |\n");
    printf("\t\t\t|          一旦删除,就不能恢复!   |\n");
    printf("\t\t\t|                                   |\n");
    printf("\t\t\t|-----------------------------------|\n");
    gotoxy(46, 10);
      scanf("%s",&q.name);  //这个&我也不确定要还是不要,楼主试试
      i=search(q,n,st);
      if(i!=-1)
      {
         con(i,n,st);
      
         n--;  //这个好像是多余的吧
      }
      printf("\n 如果你想继续删除,请输入 1,否则请输入 2\n");  //这里没有做完整哟,     
      scanf("%d",&b);
      if(b==1)
       goto loop;
   }
  }

   唯实惟新 至诚致志
2010-12-25 23:06
快速回复:求解,为什么会运行错误??
数据加载中...
 
   



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

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