File的相关操作,fopen打开,fclose关闭,fputc写字符,fputc写字符串.
附件为生成一些.h和.c文件
#include <stdio.h> //fopen
#include <iostream.h>
#include <stdlib.h>
#define FILE_NUMBER 5
int main(void)
{
FILE *fp;
char g_head_name[50];
char g_h_f_name[50];
char g_body_name[50];
char g_b_f1_name[50];
char g_b_f2_name[50];
char g_b_f3_name[50];
int i;
for(i=1;i<=FILE_NUMBER;i++)
{
sprintf(g_head_name,"%d.h",i);
printf(g_head_name);
printf("\n");
fp=fopen(g_head_name,"wr");
if(NULL == fp)
{
cout<<"error"<<endl;
exit(1);
}
else
{
cout<<"ok"<<endl;
}
sprintf(g_h_f_name,"int test_%d(void);",i);
fputs(g_h_f_name,fp);
fclose(fp);
}
for(i=1;i<=FILE_NUMBER;i++)
{
sprintf(g_body_name,"%d.cpp",i);
printf(g_body_name);
printf("\n");
fp=fopen(g_body_name,"wr");
if(NULL == fp)
{
cout<<"error"<<endl;
exit(1);
}
else
{
cout<<"ok"<<endl;
}
fputs("#include",fp);//#include
fputc(' ',fp);//"
fputc('"',fp);//"
sprintf(g_b_f1_name,"%d.h",i);//1.h
fputs(g_b_f1_name,fp);//
fputc('"',fp);//"
fputc('\n',fp);
sprintf(g_b_f2_name,"int test_%d(void)",i);
fputs(g_b_f2_name,fp);//voit test_1(void)
fputc('\n',fp);
fputc('{',fp);
fputc('\n',fp);
sprintf(g_b_f3_name,"return %d;",i);
fputs(g_b_f3_name,fp);
fputc('\n',fp);
fputc('}',fp);
fclose(fp);
}
return 0;
}
//http://support.microsoft.com/kb/156190/zh-cn
#include <stdio.h> //fopen
#include <iostream.h>
#define FILE_NUMBER 17000
int main(void)
{
FILE *fp;
char g_head_name[50];
int i;
fp=fopen("test.cpp","wr");
for(i=1;i<=17000;i++)
{
fputs("#include",fp);//#include
fputc(' ',fp);//"
fputc('"',fp);//"
sprintf(g_head_name,"%d.h",i);//1.h
fputs(g_head_name,fp);//
fputc('"',fp);//"
fputc('\n',fp);
}
fclose(fp);
return 0;
}
文章评论(0条评论)
登录后参与讨论