第58讲,第一个程序,有两行代码看不懂
#include <stdio.h>#include <stdlib.h>
#include <time.h>
int main()
{
FILE *fp;
struct tm *p;
time_t t;
time(&t); // 这里看不懂
p = localtime(&t); // 这里看不懂
if ((fp = fopen("date.txt", "w")) == NULL)
{
printf("打开文件失败了\n");
exit(1);
}
fprintf(fp, "%d-%d-%d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday );
fclose(fp);
int year, month, day;
if ((fp = fopen("date.txt", "r")) == NULL)
{
printf("打开文件失败了\n");
exit(1);
}
fscanf(fp, "%d-%d-%d", &year, &month, &day);
printf("%d-%d-%d\n", year, month, day);
return 0;
}
自行百度time.h 中time() 和 localtime() 函数的用法
页:
[1]