As like printf()
You need to use some left and right alignments
printf()
write output to stdout
fprintf()
write output to the given output stream;
printf("%6d",num);
// if num have 3 digits then adds three more spaces at left of num.
like this only you need to use with fprintf()
In your file you have only 6 digits in the maximum number.
replace all %ld
with %7ld
and add \n after every 3 or 4 numbers to get perfect allignment
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);