| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 332 人关注过本帖
标题:虔诚请教大虾,这程序哪错了
只看楼主 加入收藏
eumedees
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2009-11-30
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
虔诚请教大虾,这程序哪错了
朋友录,并按出生年顺序排列
#include<stdio.h>
struct birth_list{
 int year;
 int month;
 int day;
};
struct friends_list{
 char name[10];
 struct birth_list birthday;。。。。嵌套结构
 char telephone[13];
};
void bubble(struct friends_list *,int);。。。调用函数冒泡排序
int main(void)
{
 struct friends_list friends[10];
 struct friends_list *f=friends;
 int i,n;
 printf("Enter n:");
 scanf("%d",&n);
 for(i=0;i<n;i++,f++){
  printf("Enter friend imformation:");
  scanf("%s%d%d%d%s",(*f).name,&(*f).birthday.year,&(*f).birthday.month,&(*f).birthday.day,(*f).telephone);。。。。。输入信息
 }
 bubble(f,n);
 for(i=0;i<n;i++,f++){。。。。。打印结果
  printf("%s",(*f).name);
 }
 return 0;
}
void bubble(struct friends_list *f,int n)
{
 int i,j;
 struct friends_list temp;
 for(i=1;i<n;i++)
  for(j=0;j<n-i;j++){
      if(f[j].birthday.year>f[j+1].birthday.year){
    temp=f[j];
    f[j]=f[j+1];
    f[j+1]=temp;
      }
  }
}
2009-12-25 17:58
liangwenbc
Rank: 3Rank: 3
来 自:广州
等 级:论坛游侠
帖 子:168
专家分:174
注 册:2008-6-11
收藏
得分:8 
先说我不是大虾
#include<stdio.h>
struct birth_list
{
int year;
int month;
int day;
};
struct friends_list
{
char name[10];
struct birth_list birthday;
char telephone[13];
};
void bubble(struct friends_list *,int);
int main(void)
{
struct friends_list friends[10];
struct friends_list *f=friends;
int i,n;
printf("Enter n:");
scanf("%d",&n);
for(i=0;i<n;i++,f++)
{
  printf("Enter friend imformation:");
  scanf("%s%d%d%d%s",(*f).name,&(*f).birthday.year,&(*f).birthday.month,&(*f).birthday.day,(*f).telephone);
}
f=friends;/*因为你进行数据输入操作的时候已使指针指向后面了,所以要重新调整指针才能进行输出操作*/
bubble(f,n);
for(i=0;i<n;i++,f++){
  printf("%s",(*f).name);
}
getch();
return 0;
}
void bubble(struct friends_list *f,int n)
{
int i,j;
struct friends_list temp;
for(i=1;i<n;i++)
  for(j=0;j<n-i;j++)
      if(f[j].birthday.year>f[j+1].birthday.year){
    temp=f[j];
    f[j]=f[j+1];
    f[j+1]=temp;
      }

}

qq7434391
2009-12-25 21:30
eumenides
Rank: 2
等 级:论坛游民
帖 子:18
专家分:36
注 册:2009-12-25
收藏
得分:12 
#include<stdio.h>
struct birth_list{
 int year;
 int month;
 int day;
};
struct friends_list{
 char name[10];
 struct birth_list birthday;
 char telephone[13];
};
void bubble(struct friends_list *,int);
int main(void)
{
 struct friends_list friends[10];
 struct friends_list *f=friends;
 int i,n;
 printf("Enter n:");
 scanf("%d",&n);
 for(i=0;i<n;i++){
  printf("Enter friend imformation:");
  scanf("%s%d%d%d%s",f[i].name,&f[i].birthday.year,&f[i].birthday.month,&f[i].birthday.day,f[i].telephone);
 }
 bubble(f,n);
 for(i=0;i<n;i++,f++){
  printf("%s\n",(*f).name);
 }
 return 0;
}
void bubble(struct friends_list *f,int n)
{
 int i,j;
 struct friends_list temp;
 for(i=1;i<n;i++)
  for(j=0;j<n-i;j++){
   if(f[j].birthday.year>f[j+1].birthday.year){
    temp=f[j];
    f[j]=f[j+1];
    f[j+1]=temp;
   }
  }
}

2009-12-25 22:11
快速回复:虔诚请教大虾,这程序哪错了
数据加载中...
 
   



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

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