//******************************************************************************
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
//日期十进制int转字符显示----month/day/hour/minute/second
char *date_change(int date, char *changeto_char)
{
changeto_char[0] = date/10 + 48;
changeto_char[1] = date%10 + 48;
printf("changeto_char:%s\n",changeto_char);
return changeto_char;
}
//日期十进制int转字符显示----year
char * year_change(int date,char changetoyear_char[4] )
{
changetoyear_char[0] = date/1000 + 48;
changetoyear_char[1] = (date-changetoyear_char[0]*1000)/100 + 48;
changetoyear_char[2] = (date-changetoyear_char[0]*1000-changetoyear_char[1]*100)/10 + 48;
changetoyear_char[3] = date%10 + 48;
printf("changetoyear_char:%s\n",changetoyear_char);
return changetoyear_char;
}
void main()
{
//char a[] = "32";
//printf("%d\n", a[0]-'0'); //输出第一个字符串字符
//printf("%c\n", a[0]); //输出第一个字符串字符
unsigned char changetoyear_char[4] = {0}; //全局变量,局部变量出警告
unsigned char changeto_char[32] = {0}; //全局变量,局部变量出警告
int save_date[60] = {0};
//时间的限制:
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); /*取得当地时间*/
unsigned int date_year = (1900+p->tm_year);
unsigned int date_mon = ( 1+p->tm_mon);
unsigned int date_mday = p->tm_mday;
unsigned int date_hour = p->tm_hour;
unsigned int date_min = p->tm_min;
sprintf(changeto_char, "%d_%d_%d_%d_%d", date_year, date_mon, date_mday, date_hour, date_min);
printf("changeto_char is :%s \n", changeto_char);
//创建一个文件********************************************************************
char addr_hour[32] = "/root/zy/telnet/";
strcat(addr_hour,changeto_char); //剪切文件名,按时间写入
printf("addr_hour is :%s\n", addr_hour);
int fd = open (addr_hour,O_CREAT|O_RDWR);
sleep(3);
//删除一个文件********************************************************************
printf("删除文件 is :%s\n", addr_hour);
remove(addr_hour);
memset(changeto_char, 0, 32);
date_change(date_mday, changeto_char);
char addr_mday[32] = "/root/zy/telnet/";
strcat(addr_mday,changeto_char);
//创建一个文件******************************************************
int fd1 = open (addr_mday,O_CREAT|O_RDWR);
sleep(3);
//删除一个文件******************************************************
printf("删除文件 is :%s\n", addr_mday);
remove(addr_mday);
//获得当前的时间:,并准备把当前的时间转换为文件
//write_log.c
#include <stdio.h>#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
//日期十进制int转字符显示----month/day/hour/minute/second
char *date_change(int date, char *changeto_char)
{
changeto_char[0] = date/10 + 48;
changeto_char[1] = date%10 + 48;
printf("changeto_char:%s\n",changeto_char);
return changeto_char;
}
//日期十进制int转字符显示----year
char * year_change(int date,char changetoyear_char[4] )
{
changetoyear_char[0] = date/1000 + 48;
changetoyear_char[1] = (date-changetoyear_char[0]*1000)/100 + 48;
changetoyear_char[2] = (date-changetoyear_char[0]*1000-changetoyear_char[1]*100)/10 + 48;
changetoyear_char[3] = date%10 + 48;
printf("changetoyear_char:%s\n",changetoyear_char);
return changetoyear_char;
}
void main()
{
//char a[] = "32";
//printf("%d\n", a[0]-'0'); //输出第一个字符串字符
//printf("%c\n", a[0]); //输出第一个字符串字符
unsigned char changetoyear_char[4] = {0}; //全局变量,局部变量出警告
unsigned char changeto_char[32] = {0}; //全局变量,局部变量出警告
int save_date[60] = {0};
//时间的限制:
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); /*取得当地时间*/
unsigned int date_year = (1900+p->tm_year);
unsigned int date_mon = ( 1+p->tm_mon);
unsigned int date_mday = p->tm_mday;
unsigned int date_hour = p->tm_hour;
unsigned int date_min = p->tm_min;
sprintf(changeto_char, "%d_%d_%d_%d_%d", date_year, date_mon, date_mday, date_hour, date_min);
printf("changeto_char is :%s \n", changeto_char);
//创建一个文件********************************************************************
char addr_hour[32] = "/root/zy/telnet/";
strcat(addr_hour,changeto_char); //剪切文件名,按时间写入
printf("addr_hour is :%s\n", addr_hour);
int fd = open (addr_hour,O_CREAT|O_RDWR);
sleep(3);
//删除一个文件********************************************************************
printf("删除文件 is :%s\n", addr_hour);
remove(addr_hour);
memset(changeto_char, 0, 32);
date_change(date_mday, changeto_char);
char addr_mday[32] = "/root/zy/telnet/";
strcat(addr_mday,changeto_char);
//创建一个文件******************************************************
int fd1 = open (addr_mday,O_CREAT|O_RDWR);
sleep(3);
//删除一个文件******************************************************
printf("删除文件 is :%s\n", addr_mday);
remove(addr_mday);
}