Porting BASIC text mangling app to Objective-C
Porting BASIC text mangling app to Objective-C
- Subject: Porting BASIC text mangling app to Objective-C
- From: Ricardo Balderas <email@hidden>
- Date: Wed, 25 Mar 2009 00:06:33 -0600
Hello,
I'm pretty much new to Xcode. I've fiddled with it before and made
some simple things successfuly but never really understood how it
works, so currently I'm reading Become an Xcoder ( http://www.cocoalab.com/?q=becomeanxcoder
) and it's been very helpful in understanding Xcode and Objective-C.
Reading it also gave me the idea of porting a simple utility I made
long ago in Metal BASIC which took a text file, randomly reordered the
words in it and printed them to a new text file. Unfortunately Metal
doesn't run properly anymore, so the only chance to have this app
again is to rewrite it, which seems to make for a good simple enough
project to learn Xcode. Luckily I saved the source code, so it
shouldn't be something too hard to figure out.
I'm starting with a Cocoa Document Based project, but am having
trouble with Opening and Saving of documents. The stump comments in
MyDocument.m are beyond me still, and I've tried the "Building a Text
Editor in 15 minutes" example, but the opening and saving documents
part is a bit outdated and gets confusing. Could you help me with a
simple and well explained sample code of how to Open and Save files?
Also, how can I make the app save .txt or .rtf files? I managed to
make it output .???? files and read them back, but trying to add other
file types (taken from the TextEdit source code) led to problems
reopening a saved file.
In case you're interested, here is the original BASIC sample code:
file$=open dialog$
if file$="" then end
randomize timer
f=open file(file$) // Counts the number of words in the document
i=0
repeat
fread f,word$
i=i+1
until eof(f)
close file f
dim words$(i)
f=open file(file$) // Reads the words in a document and stores
each in an array slot
i=0
repeat
fread f,words$(i)
i=i+1
until eof(f)
close file f
dim newWords$(i),wordUsed(i)
pickNewWord:
for a=0 to i
repeat
whichWord=random(i) //Picks at random one of the words stored in
the array. If the word is already used, tries picking again.
until wordUsed(whichWord)=0
wordUsed(whichWord)=1
newWords$(a)=words$(whichWord) //stores the reordered words in a
new array
next a
fstring$=""
for a=0 to i-1
fstring$=fstring$+newWords$(a)+" " //Prints the reordered words to a
new string
next a
save$=save dialog$
if save$="" then end
f=open file(save$)
fwrite f, fstring$
close file f
Thanks
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden