Chu279 2021-05-18 16:21 采纳率: 10%
浏览 27
已结题

求C语言题目!谢谢

求C语言题目!谢谢
  • 写回答

1条回答 默认 最新

  • Jaz_羯 2021-05-18 17:32
    关注

    思路大概这样吧,纯手打没调试过,有报错的修复一下。

     

    
    #include <stdbool.h>
    #include <stdint.h>
    #include <stdlib.h>
    #include <math.h>
    
    typedef struct
    {
      char strProvince[2];    //省份编号
      char strCity[2];        //地市编号
      char strCounty[2];      //区县编号
      char strYear[4];        //出生年份
      char strMonth[2];       //出生月份
      char strDay[2];         //出生日子
      char strGender[3];      //性别
      char strCRC[1];         //校验
      char strEOF[1];         //结束符
    }T_PERSON_ID;
    
    
    char strPerson_ID[18] = {"11010219650321XXXX\0"};
    
    
    void main()
    {
        uint8_t i_scan = 0;
    
        uint8_t len_temp = 0;
    
        int16_t result_year = -1;         //出生年份
        int8_t result_month = -1;         //出生月份
        int8_t result_day = -1;           //出生日子
    
        int16_t result_gender = -1;       //性别(男:0;女:1)
    
    
        T_PERSON_ID *ppreson_id = NULL;
    
    
        /* 指针重指向 */
        ppreson_id = (T_PERSON_ID *)strPerson_ID;
    
    
        #if 1    //atoi方式
    
        /** 出生年月 ***************************************************************/
    
        result_year = atoi(ppreson_id->strYear);
        result_month = atoi(ppreson_id->strMonth);
        result_day = atoi(ppreson_id->strDay);
    
    
        /** 性别 ******************************************************************/
    
        result_gender = (atoi(ppreson_id->strDay) % 2) ? 0 : 1;
    
        #else    //非atoi方式
    
    
        /** 出生年月 ***************************************************************/    
    
        len_temp = sizeof(ppreson->strYear)
        for(i_scan = 0; i_scan < len_temp; i_scan++)
        {
            result_year += (ppreson->strYear[i_scan] - '0') * pow(10, len_temp - i_scan - 1);
        }
        
        len_temp = sizeof(ppreson->strMonth)
        for(i_scan = 0; i_scan < len_temp; i_scan++)
        {
            result_month += (ppreson->strMonth[i_scan] - '0') * pow(10, len_temp - i_scan - 1);
        }
        
        len_temp = sizeof(ppreson->strDay)
        for(i_scan = 0; i_scan < len_temp; i_scan++)
        {
            result_day += (ppreson->strDay[i_scan] - '0') * pow(10, len_temp - i_scan - 1);
        }
    
    
        /** 性别 ******************************************************************/
    
        len_temp = sizeof(ppreson->strGender)
        for(i_scan = 0; i_scan < len_temp; i_scan++)
        {
            result_gender += (ppreson->strGender[i_scan] - '0') * pow(10, len_temp - i_scan - 1);
        } 
        result_gender = (result_gender_man % 2) ? 0 : 1;
    
        #endif
    }
    
    
    评论

报告相同问题?