给个我自己写的程序,你自己修改下吧应该可以实现你说的功能
/************************************************************************/
/*
程序说明:
首先输入指令,
r为读出mynotexe.dll中的数据,
w为写入数据进mynotexe.dll
作者:love24114
*/
/************************************************************************/
#include <stdio.h>
#include <time.h>
#include <stdio.h>
/************************************************************************/
void WriteTime()
{
FILE *FilePointer;
time_t rawtime;
struct tm * timeinfo;
if ((FilePointer = fopen("mynotexe.dll", "a")) == NULL)
{
printf("打开文件失败!\n");
}
time(&rawtime );
timeinfo = localtime(&rawtime );
fprintf (FilePointer,"======%4d-%02d-%02d %02d:%02d:%02d======\n",
1900+timeinfo->tm_year,1+timeinfo->tm_mon,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);
//
fprintf(FilePointer,"%s",asctime(timeinfo));
fclose(FilePointer);
}
/************************************************************************/
void WriteInNotexe()
{
int c;
FILE *FilePointer;
WriteTime();
if ((FilePointer = fopen("mynotexe.dll", "a")) == NULL)
{
printf("打开文件失败!\n");
}
while ((c=getc(stdin))!=EOF)
fputc(c,FilePointer);
fclose(FilePointer);
}
/************************************************************************/
void ReadNotexe()
{
int c;
FILE *FilePointer;
if ((FilePointer=fopen("mynotexe.dll","r"))==NULL)
{
puts("打开文件失败!");
}
while ((c=fgetc(FilePointer)) !=EOF)
{
printf("%c",c);
}
puts(" ");
fclose(FilePointer);
}
/************************************************************************/
void yanzhen()
{
char myzl = 'z';
puts("……请输入指令……");
scanf("%c",&myzl);
if (myzl == 'w')
{
puts("指令输入正确。请写入内容……");
WriteInNotexe();
}
else
{
if (myzl == 'r')
{
puts("指令输入正确。开始读出……");
ReadNotexe();
}
else
puts("无该指令。退出程序!");
}
}
/************************************************************************/
int main(int argc, char *argv[])
{
yanzhen();
return 0;
}
[
本帖最后由 love24114 于 2011-12-22 19:44 编辑 ]