一个小程序,VC6上通过,在屏幕上输入字符,可在D盘按序号生成500个相同的文件
#include "stdio.h"
#include "iostream.h"
#include "stdlib.h"
#include "string.h"
#define OK
void main()
{
int i;
char sFilename[18];
char sFile[4];
FILE *fp[500];
for(i=0;i<=499;i++)
{
itoa(i,sFile,10);
strcpy(sFilename,"d:\\liwei");
strcat(sFilename,sFile);
strcat(sFilename,".txt");
if((fp[i]=fopen(sFilename,"wt+"))==NULL)
{
cout<<"Can not open these file!"<<endl;
return;
}
}
// file point sucess!
cout<<"File point create sucess!"<<endl;
char ch;
int n=0;
cout<<"Please input the some char you want to make file:"<<endl;
ch=getchar();
while(ch!='\n')
{
for(i=0;i<=499;i++)
{
fputc(ch,fp[i]);
}
ch=getchar();
n++;
}
cout<<n<<"char"<<"write in file!"<<endl;
cout<<"500 file created!"<<endl;
for(i=0;i<=499;i++)
{
fclose(fp[i]);
}
while(1)
{
}
}