一个小程序,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)
{
}
}
----------------解决方案--------------------------------------------------------
好象病毒的效果。。。
----------------解决方案--------------------------------------------------------
运行不了,有错误啊!
----------------解决方案--------------------------------------------------------
用500次的循环加上这两句,
itoa(i,sFile,10);
strcat(sFilename,sFile);
很简单却很狡猾,呵。
----------------解决方案--------------------------------------------------------
这不是c++吗?不懂
----------------解决方案--------------------------------------------------------