源码文件复制工具 for ACMer

介于每次在OJ上做完一题要手动复制粘贴保存一份源文件,所以自己写了一个简单的工具代替手动操作,现与大家分享。

功能

1、提供源文件复制到指定目录的功能;

2、在文件目标文件开始部分加了文件信息,如下:

/*-------------------------------*/
/* Problem: POJ 1742
/* Author:  zz_zigzag
/* Date:    2012/05/21 20:58:09
/*-------------------------------*/
3、生成一个Record文件记录文件列表信息,如下格式:

Problem ID: 3823           	Date: 2012/05/18 21:11:13	FileLength: 1030B
Problem ID: LightOJ 1214   	Date: 2012/05/19 15:14:48	FileLength: 449B
Problem ID: LightOJ 1112   	Date: 2012/05/19 15:42:57	FileLength: 1903B
Problem ID: LightOJ 1136   	Date: 2012/05/19 16:02:26	FileLength: 677B
Problem ID: DLUT 1167      	Date: 2012/05/21 14:21:04	FileLength: 1089B
Problem ID: LightOJ 1292   	Date: 2012/05/21 15:11:38	FileLength: 764B

运行说明

1、之前需要手动在C:\Program Files\MakeSourceFile\下创建Configure.ini文件,内容包括源文件路径、目标文件路径。记录(Record)文件路径,格式如下:

SourceFilePath=C:\C\Test\main.c
DestinationFilePaht=C:\Users\zz_zigzag\Dropbox\my c\HDU\
RecordFilePaht=C:\Users\zz_zigzag\Dropbox\my c\HDU\Record.cpp

2、运行时提示输入题目名称,此时需要输入欲保存的完整文件名称(带扩展名) 。


CPP源码

读者可根据自己需要自行修改:

#include 
#include 
#include 
#include 

const int M=10000,N=100;
char a[M],FileName[N];
int FileLength;
tm *local;
time_t t;
char SourceFilePath[N],DestinationFilePath[N],RecordFilePath[N];

void Get(char a[],FILE *F)
{
    fgets(a,N,F);
    a[strlen(a)-1]=0;
    return ;
}
void ReadConfigure()
{
    FILE *F=fopen("C:\\Program Files\\MakeSourceFile\\Configure.ini","r");
    fscanf(F,"%*[^=]%*c%*[ ]");Get(SourceFilePath,F);
    fscanf(F,"%*[^=]%*c%*[ ]");Get(DestinationFilePath,F);
    fscanf(F,"%*[^=]%*c%*[ ]");Get(RecordFilePath,F);
    fclose(F);
    int t=open(SourceFilePath,O_WRONLY);
    FileLength=filelength(t);
    fclose(F);
    return ;
}
void Output()
{
    puts("Please input the Problem ID:");
    Get(FileName,stdin);
    strcat(DestinationFilePath,FileName);
    freopen(SourceFilePath,"r",stdin);
    freopen(DestinationFilePath,"w",stdout);
    for(int i=strlen(FileName)-1;i>=0;i--)
    {
        if(FileName[i]=='.')
        {
            FileName[i]=0;
            break;
        }
    }
/******Add remarks******/
    t=time(NULL);
    local=localtime(&t);
    puts("/*-------------------------------*/");
    printf("/* Problem: %s\n",FileName);
    puts("/* Author:  zz_zigzag");
    printf("/* Date:    %4d/%02d/%02d %02d:%02d:%02d\n",local->tm_year+1900,\
    local->tm_mon+1,local->tm_mday, local->tm_hour,local->tm_min,local->tm_sec);
    puts("/*-------------------------------*/");
    printf("\n");
/**********************/
    while(gets(a)!=NULL)
    {
        puts(a);
    }
}
void Record()
{
    FILE *F;
    F=fopen(RecordFilePath,"at+");
    fprintf(F,"Problem ID: %-15s\tDate: %4d/%02d/%02d %02d:%02d:%02d\tFileLength: %dB\n",FileName,local->tm_year+1900,\
    local->tm_mon+1,local->tm_mday, local->tm_hour,local->tm_min,local->tm_sec,FileLength);
    fclose(F);
}
int main()
{
    ReadConfigure();
    Output();
    Record();
    return 0;
}

你可能感兴趣的:(工具,其他,工具,date,output,file,c,null)