day4——base_c

1、终端输出一个金字塔:#include <stdio.h>
#include <stdio.h>
int main(int argc, const char *argv[])
{
    int i =0,j=0,k=0,line=0;
    char c =0;
    printf("请输入需要几层金字塔");
    scanf("%d",&line);
    while(i<line){
        j=0;    
        k=0;
    while(j++<line-i){
    putchar(' ');
    //j++;
    }
    while(k<i*2+1){
    putchar('*');
    k++;
    }
    i++;
    putchar('\n');
    }
    return 0;
}

2、终端输出一个类似下图得图形

 #include <stdio.h>
int main(int argc, const char *argv[])
{
    int i =0,j =0,k=0;
    char c=0;
    while(i<6){
        k=0;
        j=0;
    while(k<i){
    putchar('_');
    k++;
    }
    c = 'F';
    while(j<=i){
    putchar(c--);
    j++;
    }
    putchar('\n');
    i++;
    }
    return 0;
}

3、思维导图

 

 

### 将RTC时间转换为`tm`结构体 在嵌入式系统开发中,通常需要处理实时时钟(RTC)模块返回的时间戳并将其转换成更易读取的形式——即C标准库中的`tm`结构体。下面展示一种方法来完成这一操作。 对于大多数微控制器而言,RTC提供的是自某个纪元(通常是1970年1月1日午夜UTC)以来经过的秒数或其它单位表示形式的时间计数值。为了将这种格式转化为`tm`对象,在POSIX兼容环境中可以直接利用gmtime或者localtime函数;然而,在资源受限设备上可能并不总是有这些功能可用。此时可以手动编写一个辅助函数来进行此过程: ```c #include <time.h> void rtc_to_tm(uint32_t seconds_since_epoch, struct tm* result){ const uint8_t days_in_month[] = { 31, /* January */ 28, /* February (non-leap year)*/ 31, /* March */ 30, /* April */ 31, /* May */ 30, /* June */ 31, /* July */ 31, /* August */ 30, /* September */ 31, /* October */ 30, /* November */ 31 /* December */ }; int day_of_week; unsigned long total_days; // Calculate the number of days since epoch. total_days = seconds_since_epoch / SECONDS_PER_DAY; // Determine which year it is and adjust for leap years. int year = YEAR_EPOCH_START; while ((unsigned)(total_days >= (is_leap_year(year)?DAYS_IN_LEAP_YEAR:DAYS_IN_NORMAL_YEAR))){ total_days -= (is_leap_year(year))? DAYS_IN_LEAP_YEAR : DAYS_IN_NORMAL_YEAR; ++year; } // Now determine what month we're in by subtracting off full months until less than one remains. int month = 0; do{ if(month==1 && is_leap_year(year)){ if(total_days>=days_in_month[month]+1){ // Leap Year Adjustment total_days-=days_in_month[month]+1; month++; } }else{ if(total_days>=days_in_month[month]){ total_days-=days_in_month[month]; month++; } } }while (++month<=12); // The remaining 'total_days' now represents just today's date within this particular month/year combination. // Compute hour/minute/second from remainder after dividing out whole days. int secs_into_day = seconds_since_epoch % SECONDS_PER_DAY; int hours = secs_into_day / SECS_PER_HOUR; int minutes = (secs_into_day % SECS_PER_HOUR)/SECS_PER_MINUTE; int seconds = secs_into_day%SECS_PER_MINUTE; // Fill up our output structure with computed values. memset(result, '\0', sizeof(*result)); result->tm_sec=seconds; result->tm_min=minutes; result->tm_hour=hours; result->tm_mday=(int)total_days+1; // Day starts at 1 not zero! result->tm_mon=month-1; // Months start counting from Jan as 0 rather than 1. result->tm_year=year-YEAR_EPOCH_START;// Years are relative to EPOCH base value. } ``` 上述代码片段展示了如何创建名为`rtc_to_tm()`的功能[^1],该功能接受来自RTC硬件寄存器的一个整型参数作为输入,并填充给定指针指向的目标`struct tm`实例。注意这里假设传入的时间是以Unix Epoch为基础计算得出的秒级精度值。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值