| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 213 人关注过本帖
标题:再次求助程序调试!
只看楼主 加入收藏
晓寒忆梦
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-10-25
收藏
 问题点数:0 回复次数:0 
再次求助程序调试!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100
typedef struct invetory
{char name[16];
int NO;
char mobile[20];
char hometele[15];
char sex;
}INVE;
void displayMenu();
int choiceItem(void);
void input(INVE inv[],int n);
int search(INVE inv[],int n);
int DeleteRecord(INVE inv[],int
void AlterRecord(INVE inv[],int n);
main(){
INVE inv[N];
int choice;
choice=choiceItem();
do{switch(choice)
{case 1:input(inv,N);
case 2:search(inv,N);
case 3:DeleteRecord(inv,N);
case 4:AlterRecord(inv,N);
}
}while(choice!=0);
printf("\n Exit!!");
}
void displayMenu()
{printf("\n=======Menu======\n");
printf("\n1........input information\n");
printf("\n2.........search information\n");
printf("\n3.........delete information\n");
printf("\n4.........alter information\n");
printf("\n0......Exit\n");
printf("\nChoice:");
}
int choiceItem(void)
{int choice;
char line[80];
do{
displayMenu();
gets(line);
choice=atoi(line);
}while(choice<0||choice>4);
return choice;}
void input(INVE inv[],int n)
{int i;
printf("\nEnter the information:");
for(i=0;i<n;i++)
scanf("%d%s%s%s%s",&inv[i].NO,inv[i].name,inv[i].mobile,inv[i].hometele,inv[i].sex);
printf("\n");
printf("\ndisplay input information:");
for(i=0;i<n;i++)
printf("\n%d%s%s%s%s",inv[i].NO,inv[i].name,inv[i].mobile,inv[i].hometele,inv[i].sex);
}
int search(INVE inv[],int n)
{int key,i=0;
printf("\nEnter the search key:");
scanf("%d",&key);
if(key<0||key>n)return 0;
else {while(i<n)
{if(inv[i].NO==key)
printf("\nthe searching information is %d%s%s%s%s",inv[i].NO,inv[i].name,inv[i].mobile,inv[i].hometele,inv[i].sex);
else i++;
}
return 1;
}
int DeleteRecord(INVE inv[],int n)
{int key,i=0,j;
printf("\nplease enter a key:");
scanf("%d",&key);
if(key<0||key>n)return error;
else{while(i<n)
{if(inv[i].NO==key)
{j=i+1;printf("the delete record is %d%s%s%s%s",inv[i].NO,inv[i].name,inv[i].mobile,inv[i].hometele,inv[i].sex);}
else i++;
}
n--;
printf("After deleteing dejust other records:");
for(j=i+1;i<n;j++)
{inv[j-1].NO=inv[j].NO;
inv[j-1].name=inv[j].name;
inv[j-1].mobile=inv[j].mobile;
inv[j-1].hometele=inv[j].hometele;
inv[j-1].sex=inv[j].sex;
}
printf("After dejusting the new order:");
for(i=0;i<n;i++)
printf("\nthe new order is %d%s%s%s%s\n",inv[i].NO,inv[i].name,inv[i].mobile,inv[i].hometele,inv[i].sex);
}
void AlterRecord(INVE inv[],int n)
{int key,i=0;
printf("\n Enter a key:");
scanf("%d",&key);
if(key<0||key>n)printf("there is no this record.");
else {while(i<n)
{if(inv[i].NO==key){
printf("please dispaly the old record:");
printf("\n%d%s%s%s%s",inv[i].NO,inv[i].name,inv[i].mobile,inv[i].hometele,inv[i].sex);
printf("\nplease input new information:");
scanf("%d%s%s%s%s",&inv[i].NO,inv[i].name,inv[i].mobile,inv[i].hometele,inv[i].sex);
}
else i++;
}
}

printf("After alter the whole new records:");
for(i=0;i<n;i++)
printf("%d%s%s%s%s\n",inv[i].NO,inv[i].name,inv[i].mobile,inv[i].hometele,inv[i].sex);
}

2007-10-28 11:26
快速回复:再次求助程序调试!
数据加载中...
 
   



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

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