| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 324 人关注过本帖
标题:关于函数参数循环的问题
只看楼主 加入收藏
Timber
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2010-1-31
结帖率:71.43%
收藏
 问题点数:0 回复次数:0 
关于函数参数循环的问题
#include <stdio.h>
#define HOUR 60

typedef struct {
int hour;
int minute;
} Ttime ;

void read(Ttime *,char *);
Ttime cal(Ttime *,Ttime *);//declaration
void print(Ttime,char *);
int compare_times(Ttime , Ttime);

int main () {
    Ttime start,end;
    Ttime time_print;
    Ttime time[3]={0};
   
    read(&start,"please enter the starting time for leg1\n");
    read(&end,"please enter the ending time for leg1\n");

    compare_times(start, end);

    if (compare_times(start, end) == -1)
    printf("\nstarting time is earlier\n");
    if (compare_times(start, end) == 0)
    printf("\nTimes are equal\n");
    while (compare_times(start, end) == 1){
    printf("\nthe starting time is later,try again!!!\n");
    read(&start,"please enter the starting time for leg1\n");
    read(&end,"please enter the ending time for leg1\n");
    }

    time_print=cal(&start,&end);
    for(int i=0;i<3;i++){
        time[i]=time_print;
    }
    print(time_print,"the duration time is");

    fflush(stdin);
    getchar();
    return 0;

}


void read(Ttime *p,char *prompt){
    int time1,time2;

    printf("\n%s",prompt);
    scanf("\n%d %d",&time1,&time2);
    p->hour=time1;
    p->minute=time2;

}

Ttime cal(Ttime *stime,Ttime *etime){
    int time;
    Ttime time_return;

    time=(etime->hour*HOUR+etime->minute)-(stime->hour*HOUR+stime->minute);

    time_return.hour=time/HOUR;
    time_return.minute=time%HOUR;

    return time_return;
}

int compare_times(Ttime t1, Ttime t2){
    if(t1.hour>t2.hour||(t1.hour==t2.hour&&t1.minute>t2.minute))
        return 1;
    if(t1.hour==t2.hour&&t1.minute==t2.minute)
        return 0;
    if(t1.hour<t2.hour||(t1.hour==t2.hour&&t1.minute<t2.minute))
        return -1;
    }

void print(Ttime time,char *prompt){

    printf("%s %d hour(s) %d minute(s)",prompt,time.hour,time.minute);
}

题目要求提问
Enter starting time for leg 1 :
Enter ending time for leg 1 :
Enter starting time for leg 2 :
Enter ending time for leg 2:
Enter starting time for leg 3 :
Enter ending time for leg 3 :

但是这里的"Enter starting time for leg1"字符串指针作为函数参数输入的,请问如何实现比如一个for循环让它自动地显示123呢?
要求只能修改main函数,执行函数不能修改
2011-01-26 10:36
快速回复:关于函数参数循环的问题
数据加载中...
 
   



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

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