二維碼
企資網

掃一掃關注

當前位置: 首頁 » 企業資訊 » 熱點 » 正文

輸入某年某月某日返回星期幾(C語言標準庫)

放大字體  縮小字體 發布日期:2021-12-17 02:50:24    作者:百里展楓    瀏覽次數:68
導讀

//wday函數參數接受格式如://20000308//此函數返回值如:"星期三"#includestdio.h#includetime.h#includestdlib.h#includestring.hchar* wday(char *date){ char *p=date; char *wd[]={"星期日",&#

//wday函數參數接受格式如:

//20000308

//此函數返回值如:"星期三"

#include<stdio.h>

#include<time.h>

#include<stdlib.h>

#include<string.h>

char* wday(char *date)

{

char *p=date;

char *wd[]=

{

"星期日",

"星期一","星期二",

"星期三","星期四",

"星期五","星期六",

"unknown"

};

struct mydate

{

int year;

char years[10];

int mon;

char months[5];

int mday;

char mdays[5];

}mydate;

strncpy(

mydate.years,date,4);

mydate.year=

atoi(mydate.years);

mydate.months[0]=

*(p+4);

mydate.months[1]=

*(p+5);

mydate.months[2]=

'\0';

mydate.mon=

atoi(mydate.months);

mydate.mdays[0]=

*(p+6);

mydate.mdays[1]=

*(p+7);

mydate.mdays[2]=

'\0';

mydate.mday=

atoi(mydate.mdays);

struct tm Timestr;

Timestr.tm_year=

mydate.year-1900;

Timestr.tm_mon=

mydate.mon-1;

Timestr.tm_mday=

mydate.mday;

Timestr.tm_hour=0;

Timestr.tm_min=0;

Timestr.tm_sec=1;

Timestr.tm_isdst=-1;

if(mktime(&Timestr)==-1)

return wd[7];

return wd[Timestr.tm_wday];

}

int main()

{

char wstr[12];

label:

fgets(wstr,12,stdin);

printf("%s是%s\n\n",wstr,wday(wstr));

goto label;

return 0;

}

 
(文/百里展楓)
免責聲明
本文僅代表作發布者:百里展楓個人觀點,本站未對其內容進行核實,請讀者僅做參考,如若文中涉及有違公德、觸犯法律的內容,一經發現,立即刪除,需自行承擔相應責任。涉及到版權或其他問題,請及時聯系我們刪除處理郵件:weilaitui@qq.com。
 

Copyright ? 2016 - 2025 - 企資網 48903.COM All Rights Reserved 粵公網安備 44030702000589號

粵ICP備16078936號

微信

關注
微信

微信二維碼

WAP二維碼

客服

聯系
客服

聯系客服:

在線QQ: 303377504

客服電話: 020-82301567

E_mail郵箱: weilaitui@qq.com

微信公眾號: weishitui

客服001 客服002 客服003

工作時間:

周一至周五: 09:00 - 18:00

反饋

用戶
反饋

日韩欧美国产免费看清风阁