![](/img/trans.png)
[英]does fprintf write '\0' in to the file if I write a string?
[英]fprintf does not write to file
有沒有人看到,為什么 fprintf 不寫入文件而 printf 工作正常?
FILE* database;
database = fopen("database.txt", "a+");
for (x=-200; x<200; x=x+10)
{
TH1F *hist_Deg = new TH1F("h1", "title", 250, -0.5, 249.5);
for (j=5000; j<5010; j++)
{
sprintf(filename,"electronsrough/105.000000MeV/x%d/y0/process%d.txt", x,j);
FILE* pfile =fopen(filename,"r");
while(!feof(pfile))
{
fscanf(pfile, "%lf /n", &p);
hist_Deg->Fill(p);
}
fclose(pfile);
}
meana = hist_Deg->GetMean();
f->SetPoint(i, x, meana);
i=i+1;
fprintf(database, "%f\n", meana);
printf("%f\n", meana);
delete hist_Deg;
}
printf 將意思輸出到命令行,但是
文件“database.txt”已創建但仍為空。
刷新和關閉數據庫文件應該可以完成這項工作。
fprintf(database, "%f\n", meana);
fflush(database);
fclose(database);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.