格式化文件操作
我 想使用C语言把以下内容写入一个.txt文件中,但不知怎么操作比较方便??希望大家提提意见@echo off
:ProcDelay delayMSec_
setlocal enableextensions
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set start_=%%h%%i%%j%%k
:_procwaitloop
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set now_=%%h%%i%%j%%k
set /a diff_=%now_%-%start_%
if %diff_% LSS %1 goto _procwaitloop
endlocal & goto :EOF
目前我使用
#include <stdio.h>
int main()
{
FILE *output = NULL;
if((output=fopen("$.bat","w"))==NULL)
return -1 ;
fprintf(output,"@echo off\n"\
":ProcDelay delayMSec_\n"\
"setlocal enableextensions\n"\
"for /f \"tokens=1-4 delims=:. \" %%%%h in (\"%%time%%\") do set start_=%%%%h%%%%i%%%%j%%%%k\n"\
":_procwaitloop\n"\
"for /f \"tokens=1-4 delims=:. \" %%%%h in (\"%%time%%\") do set now_=%%%%h%%%%i%%%%j%%%%k\n"\
"set /a diff_=%%now_%%-%%start_%%\n"\
"if %%diff_%% LSS %%1 goto _procwaitloop\n"\
"endlocal & goto :EOF\n");
fclose(output);
return 0;
}能达到目的
但是文件中有特殊字符,比如'和%都要特别的对其进行转化,挺麻烦的