/* fprintf example */
#include <stdio.h>
int main ()
{
FILE * pFile;
int n;
char name [100];
pFile = fopen ("myfile.txt","w");
for (n=0 ; n<3 ; n++)
{
puts ("please, enter a name: ");
gets (name);
fprintf (pFile, "Name %d [%-10.10s]\n",n,name);
}
fclose (pFile);
return 0;
}
append模式设置:
char* infile[N] = //input names
char* outfile[M] = //output names
int i, j;
for (i = 0; i < N; i++){
//process input
char* mode = "ab";
if (i == 0) mode = "wb";
for (j = 0; j < M; j++){
FILE* f = fopen(outfile[j], mode);
//write to file
fclose(f);
}
}