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

Username:   Password: 
 RegisterRegister   
 Importing text files help?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gnarky




PostPosted: Fri Mar 18, 2005 3:38 pm   Post subject: Importing text files help?

Is there a way that I can import the whole content of a text file?
Please help me out.

I already know how to write stuff to a text file and get it back and all that stuff, but I want to know how to get everything all at once, from any random ".txt" file on my pc.
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: Fri Mar 18, 2005 3:45 pm   Post subject: (No subject)

okay to the importing text, dont ask questions without checking the tutorials, you are just wasting evryones time, theres plenty of tutorials on reading and writing, and how to execute any file you have to use

code:

Sys.Exec

look it up in the help file
Flikerator




PostPosted: Fri Mar 18, 2005 4:59 pm   Post subject: (No subject)

Token wrote:
okay to the importing text, dont ask questions without checking the tutorials, you are just wasting evryones time, theres plenty of tutorials on reading and writing, and how to execute any file you have to use

code:

Sys.Exec

look it up in the help file


We want to encourage people to ask questions Rolling Eyes

The turing help files don't always explain it very well, and some don't want to waste time looking for a tutorial that might not exist when they could have a thread and discuss if the had any difficulty 8)
Bacchus




PostPosted: Fri Mar 18, 2005 5:14 pm   Post subject: Re: Importing text files help?

gnarky wrote:
Is there a way that I can import the whole content of a text file?
depends on what you mean, do you want to include an entire file that will act as code or just stuff that you will need to be read
Token




PostPosted: Fri Mar 18, 2005 5:20 pm   Post subject: (No subject)

hmm i've always wondered if you could import code from a text file... i guess you could store all of the variables in the file in orded they'll be used in ur code... hmm oh well ne ways the tutorials on the reading of data from a text file... not code.. is here

http://www.compsci.ca/v2/viewtopic.php?t=5#47293
continued...
http://www.compsci.ca/v2/viewtopic.php?t=427#77057

very helpfull file I/O tutorial
http://www.compsci.ca/v2/viewtopic.php?t=6818#66063

hope that helps, if you have any specific questions let us know
Bacchus




PostPosted: Fri Mar 18, 2005 5:22 pm   Post subject: (No subject)

pretty sure you can get code from a txt file cause include is basically just copy/paste
gnarky




PostPosted: Fri Mar 18, 2005 5:39 pm   Post subject: (No subject)

Wow, thanks guys for the fast responses...anyways......

Currently im just fooling around, trying to learn turing so im no expert.

For my first question...
-I learned how to do this sort of on my own, but I have a new question, around the same topic.

This may get confusing so read carefully...

Im making a database system.
I ask the user for a name and password
Those are merged into one variable array( entrydata(1) := username + password ) and then entrydata(1) is sent to a text file.

Now say I wanted to add a new user.

How would I get the (1) in entrydata(1) to automaticlly change to a (2) when a new user desides to register?

Also...

How can I scan the whole file to find a specific entry ( say entrydata(97) ) and display only its data when its called for.

I was thinking of assigning a usernumber to each registrant when it goes to the database. And then that number would be displayed beside their info. But I dont know how to do that.

Sorry about the long read, I searched around a lot and couldn't find to much about my problem.

Thanks
Bacchus




PostPosted: Fri Mar 18, 2005 6:10 pm   Post subject: (No subject)

ok dunno all of wat ur saying,but for the certain line in a file you can do
code:
fcn GetLine (lineNum : int, filename : string) : string
    var t : string
    var file : int
    open : file, filename, get
    for line : 1 .. lineNum
        get : file, t
    end for
    result t
end GetLine
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: Fri Mar 18, 2005 6:11 pm   Post subject: (No subject)

okay i dont understand your question exactly but what i think i get is that the text file has somthing like this... providing that my username was token and my password was green,>>

tokengreen (then whatever stats asigned to my name)... is that what would be in the text file?

what you could do would be next to my name you could put my number in the array, for example num1tokengreen so when you were doing your information and u read num1tokengreen you could put



put stats(streamin(4))

that would put whatever stats1 is in your array

just a thaught Razz good luck...
gnarky




PostPosted: Fri Mar 18, 2005 6:55 pm   Post subject: (No subject)

Ok....Ive kind of answered my own questions sort of.

My situation:
You enter your desired username.
Your username is saved as username(1)
The same goes for your password (password(1))
They both get written to a '.txt' file so that the '.txt' file looks like this:

username(1) :='matt'
password(1) := 'dsgdsfsdf'

After it does this, it says "Would you like to add another user?"
If you choose yes, it will ask you all of the same questions again.

My Problem
When I try to add a new user, it assumes the new user as username(1) and password(1).
There must be some way that I can get that (1) to change everytime I try to add a user.

Once again, thanks all SO much. Very Happy
Token




PostPosted: Fri Mar 18, 2005 9:00 pm   Post subject: (No subject)

thats just the pseuto code but it gives u an idea

code:

%%pesudo code

counter :=1

loop
You enter your desired username.
Your username is saved as username(counter)
The same goes for your password (password(counter))
They both get written to a '.txt' file so that the '.txt' file looks like this:

username(coutner) :='matt'
password(counter) := 'dsgdsfsdf'

 "Would you like to add another user?"
exit when  above = no
counter+=1
end loop


there ya go! good luck Very Happy
Cervantes




PostPosted: Sat Mar 19, 2005 11:44 am   Post subject: (No subject)

I'm not too sure why you're using an array (ie. username (1)). Since you're writing everything to a text file, there's no need to store the input in an array. Especially because as soon as you restart your program, your text file will be much more 'updated' than will your array. But, if you do in fact want to use arrays, a Flexible Array might be helpful. That way, every time you want to create a new user,
code:

var user : flexible array 1 .. 0 of
  record
    name, password : string
  end record
loop %main loop
  if createNewUser then
    new user, upper (user) + 1
    get user (upper (user).name
    get user (upper (user).password
  end if
end loop
gnarky




PostPosted: Sat Mar 19, 2005 7:12 pm   Post subject: (No subject)

Ok, I figured everthing that I needed to figure out except one thing.

How do I import a full text file?

Is there a way?

If this helps, I have a program already set up to tell me the number of lines there is in the file.
Cervantes




PostPosted: Sat Mar 19, 2005 8:25 pm   Post subject: (No subject)

Make an array from 1 .. max number of lines, then read each line into the corresponding element of the array. Alternatively, if you don't know the number of lines, you could use a flexible array, and add a new element to the array with each line of the text file you read, then exit when eof.
If the text file is made by the user, you'll have to account for the fact that any one line could be longer than 255 characters. (IIRC, a Turing string that is longer than 255 characters will cause the program to crash.) If the text file is made by you, you may or may not have to account for this.
atrain




PostPosted: Sat Mar 19, 2005 9:13 pm   Post subject: (No subject)

that is probably the smartest way: make an array, and stick everything into it...

wither flexible array, or read through once before to get the ammount of lines in the thing...
then make a varible, and stick the lines into it...

good luck!!
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 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: