Page 2 of 2

Re: Creating a .txt file

PostPosted: Tue Jul 20, 2010 1:45 am
by FERdeBOER
I DID IT!! :mrgreen:

Code: Select all
FILE *f=fopen("00base.mu","w");
fprintf(f,"VERSION 3\nOWNALLIANCE 0\nDIFFICULTY 1\nTOTALNUMSIDES 1\nNUMDRIVEABLES 1\nMONTH 1\nWORLDGRID 2\nLATLONG 54.071823 -11.025635\n;\nSEASTATE %i\nMDR 0 0 0\nBOTTOMTYPE %i\nTIMEOFDAY %i\nWEATHER %i\nCLOUDHEIGHT %i\nSSP %i\n\n\nENTITY 2342 SUBENTITY\nHULLID 1\nALLIANCE 1\nPOS 554859.937500 559978.937500 -70\nPOINTS 750\nCOURSE 0\nSPEED 5\nPROB 100\nDRIVEABLE 1\nUNIQUENAME ""SSN"" \nCOMMSINTERVAL 0.000000\nTACTIC RANDOMBOX\nBOX 515385.812500 601426.937500 594334.187500 518531.031250\nAIRLOADOUT 244\nAIRCRAFT 1722 1 Alert5 0 : Alert15 1 : 0 Alert30 0 : \nEND\n", seastate, bottomtype, timeofday, weather, clouds, ssp);
fclose(f);


Making it more clear:
Code: Select all
FILE *f=fopen("00base.mu","w");
fprintf(f,"\nBOTTOMTYPE %i\nTIMEOFDAY %i", bottomtype, timeofday);
fclose(f);

So the %i places the final variables in the order written.

And now all the text appears on the text file :D

Don't relax, surely I will come back with more questions... :twisted:

Thank You all for your help!

Re: Creating a .txt file

PostPosted: Tue Jul 20, 2010 1:55 am
by Bee-Ant
Hmmm...I thought you were asking on how to keep writing on the text file without worrying on 256 character limit...
But if yes, use "a+" flag on the FILE declaration :
Code: Select all
FILE *f=fopen("yourfile.txt',"a+");

a+ will add the text from the last line, not rewrite the text from beginning.
Hope it helps :D

Re: Creating a .txt file

PostPosted: Tue Jul 20, 2010 2:50 am
by FERdeBOER
Bee-Ant wrote:Hmmm...I thought you were asking on how to keep writing on the text file without worrying on 256 character limit...
But if yes, use "a+" flag on the FILE declaration :

No, moreover, I didn't know that there was such a limit since Hblade mentioned it :roll:

Bee-Ant wrote:
Code: Select all
FILE *f=fopen("yourfile.txt',"a+");

a+ will add the text from the last line, not rewrite the text from beginning.
Hope it helps :D

Great! It's very useful for what I want to do. With this I don't need to copy all the lines, but write only the ones I want to be random.

Oh, may I ask you one more thing?
With the a+ method the problem I see is that it only works once, because repeating lines makes DW crash. So I think the solution would be copying the original file (lets call it originalmission.txt), lets say to randommission.txt and then add the modified code with a+.
Can it be done? Am I asking too much? :oops: