gpt4 book ai didi

获取缩写工作日名称的跨平台方法

转载 作者:太空宇宙 更新时间:2023-11-04 02:12:53 26 4
gpt4 key购买 nike

#include <langinfo.h>
#include <stdio.h>

int main(int argc, char **argv){

char *firstDayAb;
firstDayAb = nl_langinfo(ABDAY_1);
printf("\nFirst day ab is %s\n", firstDayAb);

return 0;
}

此代码在 Mac 和 Linux 上运行良好,但由于缺少 langinfo.h 而无法在 Windows 上运行。如何避免使用 langinfo.h?或者也许还有另一种获取缩写工作日名称的方法?

最佳答案

#include <stdio.h>
#include <time.h>

int main ()
{
struct tm timeinfo = {0};
char buffer [80];
timeinfo.tm_wday = 1;
strftime (buffer, 80, "First day ab is %a", &timeinfo);
puts (buffer);
return 0;
}

关于获取缩写工作日名称的跨平台方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11486411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com