| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 991 人关注过本帖
标题:这个程序有个函数的问题
取消只看楼主 加入收藏
fujian26
Rank: 1
等 级:新手上路
帖 子:131
专家分:0
注 册:2007-4-3
收藏
 问题点数:0 回复次数:7 
这个程序有个函数的问题

#include"stdio.h"
struct xinxi
{
char name[20];
char yuanxi[20];
long num;
int xiangmu;
int mingci;
};
struct xinxi a[50];
struct xinxi p;
void shuru()
{
int i;
char c;
for(i=0;i<50;i++)
{
printf("qing shu ru bi sai xiang mu bian hao\n");
scanf("%d",&a[i].xiangmu);
printf("\n name:\n");
scanf("%s",a[i].name);
printf("\n yuanxi \n");
scanf("%s",a[i].yuanxi);
printf("\n xuehao \n");
scanf("%ld",&a[i].num);
printf("\n ming ci \n");
scanf("%d",&a[i].mingci);
printf("\n continue yes or no? xie y|n\n");
scanf("%c",&c);
scanf("%c",&c);
if(c=='y') continue;
if(c=='n') break;
}

}
void chazhao()
{
int i,j;
long b;
printf("qing shu ru chao zhao de xue hao(0=tiaochu)\n");
scanf("%ld",&b);
printf("\n xiang mu \n");
scanf("%d",&j);
while(b!=0)
{
for(i=0;i<50;i++)
{
if(a[i].num==b&&a[i].xiangmu==j)
printf("xing ming :%s\n",a[i].name);
printf("yuan xi :%s\n",a[i].yuanxi);
printf("xiang mu :%d\n",a[i].xiangmu);
printf("xue hao: %ld\n",a[i].num);
printf("ming ci :%d\n",a[i].mingci);
}
printf("\n qing shu ru chao zhao de xue hao(0=tiaochu)\n");
scanf("%ld",&b);
printf("\n xiang mu \n");
scanf("%d",&j);
}

}
void cunchu(int n)
{
int i,j,k,h;
FILE *fw;
fw=fopen("D:\hujian.txt","w");
for(k=1;k<=n;k++)
{
printf("di %d xiang bi sai de ji lu\n",k);
fprintf(fw,"di %d xiang bi sai de ji lu\n",k);
for(h=0;h<50;h++)
{
if(a[h].xiangmu==k)
{
for(i=1;i<50;i++)
for(j=0;j<50-i;j++)
{
if(a[j].mingci>a[j+1].mingci)
{
p=a[j];a[j]=a[j+1];a[j+1]=p;
}
}

for(i=0;i<3;i++)
{
printf("%10s %10s %10ld %10d\n",a[i].name,a[i].yuanxi,a[i].num,a[i].mingci);
fprintf(fw,"%10s %10s %10ld %10d\n",a[i].name,a[i].yuanxi,a[i].num,a[i].mingci);
}

}}}
fclose(fw);
}

void shanchu(int n)
{
long b;
int a1,h,j,i,k;
FILE *fw;
fw=fopen("D:\\hujian.txt","w");
printf("qing shu ru xue hao\n");
scanf("%ld",&b);
printf("\n xiang mu \n");
scanf("%d",&a1);
for(h=0;h<50;h++)
{
if(a[h].num==b&&a[h].xiangmu==a1)
{
for(k=1;k<=n;k++)
{
fprintf(fw,"di %d xiang bi sai de ji lu\n",k);
for(i=1;i<50;i++)
for(j=0;j<50-i;j++)
{
if(a[j].mingci>a[j+1].mingci)
{
p=a[j];a[j]=a[j+1];a[j+1]=p;
}
}
for(i=h;i<50;i++)
a[i+1]=a[i];
for(i=0;i<3;i++)
{
fprintf(fw,"%10s %10s %10ld %10d\n",a[i].name,a[i].yuanxi,a[i].num,a[i].mingci);
}
}

}
}
}
int main()
{
int n,g,i,j,k;
FILE *fw;
fw=fopen("D:\\hujian.txt","w");
printf("*********** ****************** 1.shuru **************************************\n");
printf("*********** ****************** 2.chazhao **************************************\n");
printf("*********** ****************** 3.xianshi\cunchu **************************************\n");
printf("*********** ****************** 4.shanchu **************************************");
printf("\n qing xian shu ru bi sai xiang mu ge shu\n");
scanf("%d",&n);
printf("\nqing shu ru ni de xun ze(1-4)\n");
scanf("%d",&g);
while(g!=0)
{switch(g)
{
case 1:shuru();break;
case 2:chazhao();break;
case 3:cunchu(n);break;
case 4:shanchu(n);break;
default:printf("wrong\n");
}
printf("\nqing shu ru ni de xun ze(1.shuru 2.chazhao 3.cunchu\xianshi 4.shanchu 0==jiesu)\n");
scanf("%d",&g);}
return 0;
}
为什么那个cunchu函数显示不出来信息,,显示的全是0

搜索更多相关主题的帖子: 函数 
2007-08-02 16:54
fujian26
Rank: 1
等 级:新手上路
帖 子:131
专家分:0
注 册:2007-4-3
收藏
得分:0 

#include"stdio.h"
#include"string.h"
struct xinxi
{
char name[20];
char yuanxi[20];
long num;
int xiangmu;
int mingci;
};
struct xinxi a[50];
struct xinxi p;
struct xinxi b[50];
void shuru()
{
int i,j=0;
char c;
for(i=0;i<50;i++)
{
printf("qing shu ru bi sai xiang mu bian hao\n");
scanf("%d",&a[i].xiangmu);
printf("\n name:\n");
scanf("%s",a[i].name);
printf("\n yuanxi \n");
scanf("%s",a[i].yuanxi);
printf("\n xuehao \n");
scanf("%ld",&a[i].num);
printf("\n ming ci \n");
scanf("%d",&a[i].mingci);
printf("\n continue yes or no? xie y|n\n");
scanf("%c",&c);
scanf("%c",&c);
if(c=='y') continue;
if(c=='n') break;
}

}
void chazhao()
{
int i,j;
long b;
printf("qing shu ru chao zhao de xue hao(0=tiaochu)\n");
scanf("%ld",&b);
printf("\n xiang mu \n");
scanf("%d",&j);
while(b!=0)
{
for(i=0;i<50;i++)
{
if(a[i].num==b&&a[i].xiangmu==j)
{ printf("xing ming :%s\n",a[i].name);
printf("yuan xi :%s\n",a[i].yuanxi);
printf("xiang mu :%d\n",a[i].xiangmu);
printf("xue hao: %ld\n",a[i].num);
printf("ming ci :%d\n",a[i].mingci);}
}
printf("\n qing shu ru chao zhao de xue hao(0=tiaochu)\n");
scanf("%ld",&b);
printf("\n xiang mu \n");
scanf("%d",&j);
}

}
void cunchu(int n)
{
int i,j,k,g=0;
FILE *fw;
fw=fopen("E:\\fujian.txt","w");
for(i=0;i<50;i++)
{
if(a[i].xiangmu==k)
{strcpy(b[g].name,a[i].name);
strcpy(b[g].yuanxi,a[i].yuanxi);
b[g].num=a[i].num;
b[g].mingci=a[i].mingci;
g++;}}
for(k=1;k<=n;k++)
{
printf("di %d xiang bi sai de ji lu\n",k);
fprintf(fw,"di %d xiang bi sai de ji lu\n",k);
for(i=0;i<50;i++)
for(j=1;j<50-i;j++)
{
if(b[j].mingci>b[j+1].mingci)
{
p=b[j];
b[j]=b[j+1];
b[j+1]=p;
}}
for(i=0;i<3;i++)
{
printf("%10s %10s %10ld %10d\n",b[i].name,b[i].yuanxi,b[i].num,b[i].mingci);
fprintf(fw,"%10s %10s %10ld %10d\n",b[i].name,b[i].yuanxi,b[i].num,b[i].mingci);}
}

fclose(fw);
}

void shanchu(int n)
{
long b;
int a1,h,j,i,k;
FILE *fw;
fw=fopen("E:\\fujian.txt","w");
printf("qing shu ru xue hao\n");
scanf("%ld",&b);
printf("\n xiang mu \n");
scanf("%d",&a1);
for(h=0;h<50;h++)
{
if(a[h].num==b&&a[h].xiangmu==a1)
{
for(k=1;k<=n;k++)
{
fprintf(fw,"di %d xiang bi sai de ji lu\n",k);
for(i=1;i<50;i++)
for(j=0;j<50-i;j++)
{
if(a[j].mingci>a[j+1].mingci)
{
p=a[j];a[j]=a[j+1];a[j+1]=p;
}
}
for(i=h;i<50;i++)
a[i+1]=a[i];
for(i=0;i<3;i++)
{
fprintf(fw,"%10s %10s %10ld %10d\n",a[i].name,a[i].yuanxi,a[i].num,a[i].mingci);
}
}

}
}
}
int main()
{
int n,g,i,j,k;
FILE *fw;
fw=fopen("E:\\fujian.txt","w");
printf("*********** ****************** 1.shuru **************************************\n");
printf("*********** ****************** 2.chazhao **************************************\n");
printf("*********** ****************** 3.xianshi\cunchu **************************************\n");
printf("*********** ****************** 4.shanchu **************************************");
printf("\n qing xian shu ru bi sai xiang mu ge shu\n");
scanf("%d",&n);
printf("\nqing shu ru ni de xun ze(1-4)\n");
scanf("%d",&g);
while(g!=0)
{switch(g)
{
case 1:shuru();break;
case 2:chazhao();break;
case 3:cunchu(n);break;
case 4:shanchu(n);break;
default:printf("wrong\n");
}
printf("\nqing shu ru ni de xun ze(1.shuru 2.chazhao 3.cunchu\xianshi 4.shanchu 0==jiesu)\n");
scanf("%d",&g);}
fclose(fw);
return 0;
}
我把他改了一下,,但那个cunchu函数还是没有显示,,能帮我改下吗


退一步海阔天空.......
2007-08-02 18:48
fujian26
Rank: 1
等 级:新手上路
帖 子:131
专家分:0
注 册:2007-4-3
收藏
得分:0 
首先shuru功能是输入 xiangmu name yuanxi num mingci
chazhao功能是按num和xiangmu查找,并显示xiangmu name yuanxi num mingci这些信息
cunchu功能是按xiangmu来存储而且是从第一位开始存储前三位并且还要显示
如:第一项
name yuanxi num mingci
第2项
name yuanxi num mingci.........
shanchu功能是按num和xiangmu来确定删除对象并存储覆盖原文件

退一步海阔天空.......
2007-08-02 19:19
fujian26
Rank: 1
等 级:新手上路
帖 子:131
专家分:0
注 册:2007-4-3
收藏
得分:0 
院系

退一步海阔天空.......
2007-08-02 19:33
fujian26
Rank: 1
等 级:新手上路
帖 子:131
专家分:0
注 册:2007-4-3
收藏
得分:0 
K是项目

退一步海阔天空.......
2007-08-02 19:46
fujian26
Rank: 1
等 级:新手上路
帖 子:131
专家分:0
注 册:2007-4-3
收藏
得分:0 
恩,K就是项目,是用来跟踪项目的,第K项,,

退一步海阔天空.......
2007-08-02 19:50
fujian26
Rank: 1
等 级:新手上路
帖 子:131
专家分:0
注 册:2007-4-3
收藏
得分:0 

你就帮我改改,,只要满足上面的功能就行,
今天编这个程序都弄糊涂了, 谢谢了


退一步海阔天空.......
2007-08-02 19:53
fujian26
Rank: 1
等 级:新手上路
帖 子:131
专家分:0
注 册:2007-4-3
收藏
得分:0 
恩,,谢谢了

退一步海阔天空.......
2007-08-02 20:18
快速回复:这个程序有个函数的问题
数据加载中...
 
   



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

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