📄 updatetime.c
字号:
/*================================================================
/*@This program is for find the key_word,and then get the system time
/*@paste the system at the end of the key_word
/*@the params needed are the SRCfilename,Objfilename,and the key_word
==================================================================*/
/*head files*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DEFSETING 0
#define USRSETING 1
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h> //C head files
//int argc,char *argv[]
int main( )
{
/*values define*/
FILE *fpSRC=NULL;
FILE *fpOBJ=NULL;
FILE *fpparam = NULL;
int param = 0;
int linenum=0;
int num = 0;
int keystr_len;
int i = 0;
char linestr[256] = {0};
char wtmp[256] = {0};
char *timestr;
//char *replacestr = NULL;
char *linetmp = NULL;
char SRCfilename[64];
char Objfilename[64];
char key_word[64];
char line[64];
char *pfind = NULL;
char *pnext = NULL;
char *timetmp = NULL;
// char *params[3] = {NULL};
/*======================get currunt time begin===========================*/
printf("version mamager:\n");
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); /*ȡ�õ���ʱ��*/
printf("%d.%d.%d ", (1900+p->tm_year),(1+p->tm_mon), p->tm_mday);
printf("%d:%d:%d\n",p->tm_hour, p->tm_min, p->tm_sec);
time_t now; //ʵ����time_t�ṹ
struct tm *timenow; //ʵ����tm�ṹָ��
time(&now);//time������ȡ���ڵ�ʱ��(���ʱ�ʱ���DZ���ʱ��)��Ȼ����ֵ��now
timenow = localtime(&now);//localtime�����Ѵ�timeȡ�õ�ʱ��now�������������е�ʱ��(���������õĵ���)
printf("Local time is %s\n",asctime(timenow));//�Ͼ���asctime������ʱ��ת�����ַ���ͨ��printf()��������
timestr = asctime(timenow);
/*======================get currunt time end===========================*/
/*======================read the params from user==================*/
printf("checking user config...\n");
if((fpparam=fopen("params.txt","r"))!=NULL)
while(fgets(line,100,fpparam))
{
line[strlen(line)-1]='\0';//add a flag of string end
if(!memcmp("SRCfilename",line,strlen("SRCfilename")))//if find username
{
//memcpy(SRCfilename, (line+sizeof("SRCfilename")+1),(sizeof(SRCfilename)-2));
strcpy(SRCfilename,(line+sizeof("SRCfilename")+1));
SRCfilename[strlen(SRCfilename)-1] = '\0';
printf("source file name is:%s\n",SRCfilename);
continue;
}
if(!memcmp("Objfilename",line,strlen("Objfilename")))
{
//memcpy(Objfilename,(line+sizeof("Objfilename")+1),sizeof(Objfilename));
strcpy(Objfilename,(line+sizeof("Objfilename")+1));
Objfilename[strlen(Objfilename)-1] = '\0';
printf("objece file name is: %s\n",Objfilename);
continue;
}
if(!memcmp("key_word",line,strlen("key_word")))
{
memcpy(key_word,(line+sizeof("key_word")+1),sizeof(key_word));
printf("key_word is :%s\n",key_word);
break;
}
}
fclose(fpparam);
/*========================configure demo sample=========================
SRCfilename="d:\\updatetime.c";
Objfilename = "d:\\updatetimeN.c";
key_word="#define USRSETING ";
/*========================configure the params end=========================*/
if((fpOBJ=fopen(Objfilename,"wr"))==NULL)//���ó���������ʽ����
{
printf("open file error!\n");
return 0;
}
else
{
printf("open Objfilename file succed!\n");
}
if((fpSRC=fopen(SRCfilename,"rw"))==NULL)
{
printf("open Source file error!\n");
return 0;
}
else
{
while (!feof(fpSRC))
{
fgets(linestr,256,fpSRC);
// printf("read a line \n%s\n",linestr);
linenum+=1; //��������
linetmp = linestr;
/*============find the sting in this line ,and deal with it if there is the keyword preset existed== begin=======*/
keystr_len = strlen (key_word);
timetmp = timestr;
pfind = strstr (linetmp,key_word);
if(pfind!=NULL)
{
pnext = pfind + keystr_len;
*pnext='(';
pnext++;
strcpy(pnext,timetmp);
pnext[strlen(timetmp)-1]=')';
pnext[strlen(timetmp)]='\n';
pnext[strlen(timetmp)+1]='\0';
}
/*============find the sting in this line ,and deal with it if there is the keyword preset existed== end========*/
/*============write the new line to the tmp file========*/
fputs(linetmp,fpOBJ);
fflush(fpOBJ);
}
printf ("total line is%d\n",linenum);
}
fclose(fpSRC);
fclose(fpOBJ);
//system("pause");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -