一 时间操作
void ShowCurrentTime()
{
time_t tt;
time(&tt);
tm *time = localtime(&tt);
char* ws[] = {
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
};
printf("%d/%d/%d (%s) %02d:%02d:%02d
",
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, ws[time->tm_wday],
time->tm_hour, time->tm_min, time->tm_sec);
}
/*
2019/9/26 (星期四) 00:02:10
*/
int main(int argc, char *argv[], char **envp)
{
time_t tt;//long __int64
//printf("请输入你的生日:(年月日时分秒)");
time_t t1 = time(NULL);
tm time = { 35,11,9,31,11,2015 - 1900 };
tt = mktime(&time);
printf("%d", tt);
return 0;
}
/*
1451524295
*/
二 磁盘读取
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <io.h>
#include <string.h>
char sFile[256] = "System.AddIn.dll";
int IsHiden(unsigned int nAttribute)
{
return nAttribute & _A_HIDDEN;
}
int IsDirectory(unsigned int nAttribute)
{
return nAttribute & _A_SUBDIR;
}
void scanFile(char* path)
{
char s[256];
strcpy(s, path);
strcat(s, "\*.*");
struct _finddata_t fd;
intptr_t hFile = _findfirst(s, &fd);
if( hFile== -1L)
return;
do
{
if (strcmp(fd.name, ".") && strcmp(fd.name, ".."))
{
//printf("%10d %s:
", fd.size, fd.name);
if (!strcmp(fd.name, sFile))
{
if (IsDirectory(fd.attrib))
{
printf("%10s %s:
", "文件夹", fd.name);
}
else
{
puts(path);
printf("%10d %s:
", fd.size, fd.name);
}
}
//如果是目录文件就追加目录进行递归调用:
if (IsDirectory(fd.attrib))
{
char sDir[256];
strcpy(sDir, path);
strcat(sDir, "\");
strcat(sDir, fd.name);
scanFile(sDir);
}
}
//scanFile(path/xxx);
}while(_findnext( hFile ,&fd) == 0);
}
int main()
{
char s[256] = "C:";
//printf("请输入一个磁盘号或者目录名:");
//scanf_s("%s", s, sizeof(s));
scanFile(s);
}