| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 336 人关注过本帖
标题:看看这个标题排序
只看楼主 加入收藏
ljx8268771
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-12-20
收藏
 问题点数:0 回复次数:1 
看看这个标题排序
#include<stdio.h>

#define MATITL 40
#define MAAUTL 40
#define MABK 3

struct book{
    char title[MATITL];
    char author[MAAUTL];
    float value;
};
void print1(struct book guan[],int n);
void print2(struct book *ptr[],int n);

main()
{
    int count,i;
    struct book guan[MABK],*ptr2[MABK];
    char ch;
    printf("please enter the book\n");
    count=0;
    while(count<3&&gets(guan[count].title)!=NULL&&guan[count].title[0]!='\0')
    {
        printf("please enter the author\n");
        gets(guan[count].author);
        printf("please enter the value\n");
        scanf("%f",&guan[count].value);
        count++;
        ch=getchar();
        printf("please enter the book\n");
    }
    for(i=0;i<3;i++)
    {
        ptr2[i]=&guan[i];

    }
    print1(guan,3);
    printf("another input:\n");
    print2(ptr2,3);
}



void print1(struct book guan[],int n)
{
    int count;
    count=0;
    for(count=0;count<n;count++)
    {
      printf(" %s by %s:$%.2f\n",guan[count].title,guan[count].author,guan[count].value);
    }
}



void print2(struct book *ptr[],int n)//以标题先后输出
{
    int i,j;
    struct book *temp;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if((strcmp(ptr[i]->title,ptr[j]->title))>0)
            {
                temp=ptr[j];
                ptr[j]=ptr[i];
                ptr[i]=temp;
            }        
        }
        for(i=0;i<n;i++)
        {
            printf(" %s by %s:$%.2f\n",ptr[i]->title,ptr[i]->author,ptr[i]->value);
        }
    }

}
搜索更多相关主题的帖子: void include please title 
2012-12-20 21:12
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:0 
非要说错,那就是外循环多执行了一次。楼主要表达什么?


[fly]存在即是合理[/fly]
2012-12-20 21:24
快速回复:看看这个标题排序
数据加载中...
 
   



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

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