[英]how to make file alignment using fprintf in c?
我在使用C對齊文件時遇到問題
程序行:
fprintf(fpscrip,"\n %ld , %ld , %ld , %ld , %ld , %ld , %ld , %ld , %ld , %ld , %ld",scripCode,tradeVolume,LTQ,LTR,OpenRate,CloseRate,HighRate,LowRate,TotBuyQty,TotSellQty,LowerCircuitLimit,UpperCircuitLimit)
文件o / p
524667 , 7 , 1 , 34010 , 34500 , 34825 , 34500 , 34010 , 728 , 698 , 27865
533573 , 83625 , 50 , 14260 , 13655 , 13595 , 14440 , 13575 , 9202 , 15989 , 10880
結果應該像這樣打印:
524667 , 7 , 1 ,...
533573 ,83625,50,...
就像printf()
您需要使用一些左右對齊方式
printf()
將輸出寫入標准輸出
fprintf()
將輸出寫入給定的輸出流;
printf("%6d",num);
// if num have 3 digits then adds three more spaces at left of num.
像這樣,只需要與fprintf()
一起使用
您的文件中最多只能有6位數字。
將所有%ld
替換為%7ld
並在每3或4個數字后添加\\ n以得到完美的分配
fprintf(fpscrip,"\n %7ld , %7ld , %7ld , %7ld , %7ld , %7ld , %7ld , %7ld , %7ld , %7ld , %7ld ",scripCode,tradeVolume,LTQ,LTR,OpenRate,CloseRate,HighRate,LowRate,TotBuyQty,TotSellQty,LowerCircuitLimit,UpperCircuitLimit);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.