如何在1GB的C语言中生成xml文件

如何在1GB的C语言中生成xml文件,c,C,我不知道谁应该在XML标记中生成1GB的数据。 我想在1GB大小的数据文本中生成一行数据 我如何才能以最高效(速度方面)的方式实现这一点。 数据应该是可读的(当然可能是无意义的) #包括 int main(){ printf(“创建XML”); 文件*fptr; /*开放写作*/ fptr=fopen(“/tmp/emp.xml”,“w”); 如果(fptr==NULL) { printf(“文件不存在\n”); 返回1; } fprintf(fptr,“\n”); fprintf(fptr,“

我不知道谁应该在XML标记中生成1GB的数据。 我想在1GB大小的数据文本中生成一行数据 我如何才能以最高效(速度方面)的方式实现这一点。 数据应该是可读的(当然可能是无意义的)

#包括
int main(){
printf(“创建XML”);
文件*fptr;
/*开放写作*/
fptr=fopen(“/tmp/emp.xml”,“w”);
如果(fptr==NULL)
{
printf(“文件不存在\n”);
返回1;
}
fprintf(fptr,“\n”);
fprintf(fptr,“\n”);
fprintf(fptr,“25\n”);
fprintf(fptr,“新客户”);
fprintf(fptr,“dhgdhgdkrjgndliutghdnkljtgdliuthgdithugdnk…1GB_长\n”);
fprintf(fptr,“”);
fclose(fptr);
}

我通过创建三个文件解决了这个问题

一个是xml,直到打开数据应该驻留的标记为止。 第二个是生成的垃圾数据。 第三个是xml其余部分中批量数据的close标记

像这样:

   // Open two files to be merged
   FILE *fp1 = fopen("person1.xml", "r");
   FILE *fp2 = fopen("randomdata.txt", "r");
   FILE *fp3 = fopen("person3.xml", "r");


   // Open file to store the result
   FILE *fp4 = fopen("personf.xml", "w");
   char c;

   if (fp1 == NULL || fp2 == NULL || fp3 == NULL || fp4 == NULL)
   {
         puts(" --- Could not open files");
         exit(0);
   }

   // Copy contents of first file1
   while ((c = fgetc(fp1)) != EOF)
      fputc(c, fp4);

   printf(" --- Done copying file 1\n");
   // Copy contents of first file2
   while ((c = fgetc(fp2)) != EOF)
      fputc(c, fp4);

   printf(" --- Done copying file 2\n");

   // Copy contents of first file3
   while ((c = fgetc(fp3)) != EOF)
      fputc(c, fp4);

   printf(" --- Done copying file 3\n");

   printf("Merged files\n");

   fclose(fp1);
   fclose(fp2);
   fclose(fp3);
   fclose(fp4);
   return 0;

只需在循环中写入“bar”数百万次?循环打印较小的块怎么样?可能会追加到第一个标记,然后插入随机字符?最后用剩下的标签来确定它?我试试看。
   // Open two files to be merged
   FILE *fp1 = fopen("person1.xml", "r");
   FILE *fp2 = fopen("randomdata.txt", "r");
   FILE *fp3 = fopen("person3.xml", "r");


   // Open file to store the result
   FILE *fp4 = fopen("personf.xml", "w");
   char c;

   if (fp1 == NULL || fp2 == NULL || fp3 == NULL || fp4 == NULL)
   {
         puts(" --- Could not open files");
         exit(0);
   }

   // Copy contents of first file1
   while ((c = fgetc(fp1)) != EOF)
      fputc(c, fp4);

   printf(" --- Done copying file 1\n");
   // Copy contents of first file2
   while ((c = fgetc(fp2)) != EOF)
      fputc(c, fp4);

   printf(" --- Done copying file 2\n");

   // Copy contents of first file3
   while ((c = fgetc(fp3)) != EOF)
      fputc(c, fp4);

   printf(" --- Done copying file 3\n");

   printf("Merged files\n");

   fclose(fp1);
   fclose(fp2);
   fclose(fp3);
   fclose(fp4);
   return 0;