Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing program that creates a .txt file
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
NotNemesis




PostPosted: Fri Nov 20, 2015 5:11 pm   Post subject: Turing program that creates a .txt file

What is it you are trying to achieve?
Hi, I want to create a program that creates a .txt file and names it after what the user inputs.


What is the problem you are having?
Can't figure out how Turing would make a file o~o
I already understand how to have Turing read and write to a file.

Describe what you have tried to solve this problem
Tried to use Dan's "How to read and write to a file in Turing" but that's only for reading and writing a file that exists.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


var filename, filenametxt : string % File name and file name w/ .txt

put "Please type the name of the file that you want to create (no extensions, please)"
get filename

filenametxt := filename + ".txt"
put filenametxt




Please specify what version of Turing you are using
4.1 and 4.11
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Mon Nov 23, 2015 1:40 pm   Post subject: Re: Turing program that creates a .txt file

I'll try to clear it up a little bit for you.

In dan's post, he shows you how to set up a stream to write to files. if said file doesn't exist it creates one, but you need to have a path and a name for your file.

code:

var fileName: string := "blah.txt"  %%this will be what the user names their file right.
var filePath : string := "c:\\users\\%yourUSERnameHERE%\\desktop\\" %%a location, make it what you want
var fileNo : int := 1  %%this is to USE the file

put filePath + fileName %%know what \\ does


%%example to show you
if File.Exists(filePath + fileName) then
    put "it exists!"
else  %%no file was created so BOOM ONE FAULSE
    put "doesn't exist!"
    %%create it -> SEE that post again
    open : fileNo, filePath + fileName, write %%should work with put to
    close : fileNo

    %%check now to see if our file was created
    if File.Exists(filePath + fileName) then
          %%and yes, yes it was...
        put "It now exists!"
    end if
end if


cheers
NotNemesis




PostPosted: Tue Nov 24, 2015 7:47 pm   Post subject: RE:Turing program that creates a .txt file

Ohh, I get it now! Thank you Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: