| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1081 人关注过本帖
标题:结构体指针传递后对成员的遍历
只看楼主 加入收藏
数据总线
Rank: 1
等 级:新手上路
帖 子:9
专家分:7
注 册:2018-3-14
结帖率:33.33%
收藏
已结贴  问题点数:16 回复次数:1 
结构体指针传递后对成员的遍历
#include <stdio.h>
#include <stdlib.h>

typedef struct TIMEER
{
    unsigned char Year;
    unsigned char Month;
    unsigned char Day;
    unsigned char Hour;
    unsigned char Min;
    unsigned char Sec;
    unsigned char Weak;
}sTime;

sTime CurTime;

void TimeToDisp(sTime* time);

void    DISPDAY(unsigned char dat)
{
     printf("%d\n",dat);
     printf("\n");
}

void TimeToDisp(sTime* time)
{
    unsigned char *p_time = time;
    unsigned char i;
    for(i=0; i<7; i++)
    {
       DISPDAY(p_time[i]);//请问有没有比这种更好更直观的方法???
    }
}


int main()
{
    CurTime.Year = 22;
    CurTime.Month = 2;
    CurTime.Day = 9;
    CurTime.Hour = 17;
    CurTime.Min = 16;
    CurTime.Sec = 22;
    CurTime.Weak = 3;

    TimeToDisp(&CurTime);

    return 0;
}

搜索更多相关主题的帖子: unsigned char 传递 指针 void 
2022-02-09 17:34
diycai
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:147
专家分:895
注 册:2021-5-18
收藏
得分:16 
程序代码:
#include <stdio.h>
#include <stdlib.h>

typedef struct TIMEER
{
    unsigned char Year;
    unsigned char Month;
    unsigned char Day;
    unsigned char Hour;
    unsigned char Min;
    unsigned char Sec;
    unsigned char Weak;
}sTime;

sTime CurTime;

void TimeToDisp(sTime* time)
{
    printf("20%d-%02d-%02d %d:%d:%d\n", time->Year, time->Month, time->Day, time->Hour, time->Min, time->Sec);
}


int main()
{
    CurTime.Year = 22;
    CurTime.Month = 2;
    CurTime.Day = 9;
    CurTime.Hour = 17;
    CurTime.Min = 16;
    CurTime.Sec = 22;
    CurTime.Weak = 3;

    TimeToDisp(&CurTime);

    return 0;
}
2022-02-10 15:06
快速回复:结构体指针传递后对成员的遍历
数据加载中...
 
   



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

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