Computer Science Canada Importing text files help? |
Author: | gnarky [ 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. |
Author: | Token [ Fri Mar 18, 2005 3:45 pm ] | ||
Post 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
look it up in the help file |
Author: | Flikerator [ Fri Mar 18, 2005 4:59 pm ] | ||
Post 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
look it up in the help file We want to encourage people to ask questions ![]() 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) |
Author: | Bacchus [ 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 |
Author: | Token [ Fri Mar 18, 2005 5:20 pm ] |
Post 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 |
Author: | Bacchus [ Fri Mar 18, 2005 5:22 pm ] |
Post subject: | |
pretty sure you can get code from a txt file cause include is basically just copy/paste |
Author: | gnarky [ Fri Mar 18, 2005 5:39 pm ] |
Post 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 |
Author: | Bacchus [ Fri Mar 18, 2005 6:10 pm ] | ||
Post subject: | |||
ok dunno all of wat ur saying,but for the certain line in a file you can do
|
Author: | Token [ Fri Mar 18, 2005 6:11 pm ] |
Post 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 ![]() |
Author: | gnarky [ Fri Mar 18, 2005 6:55 pm ] |
Post 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. ![]() |
Author: | Token [ Fri Mar 18, 2005 9:00 pm ] | ||
Post subject: | |||
thats just the pseuto code but it gives u an idea
there ya go! good luck ![]() |
Author: | Cervantes [ Sat Mar 19, 2005 11:44 am ] | ||
Post 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,
|
Author: | gnarky [ Sat Mar 19, 2005 7:12 pm ] |
Post 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. |
Author: | Cervantes [ Sat Mar 19, 2005 8:25 pm ] |
Post 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. |
Author: | atrain [ Sat Mar 19, 2005 9:13 pm ] |
Post 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!! |
Author: | gnarky [ Sun Mar 20, 2005 12:12 pm ] | ||
Post subject: | |||
Ok, kind of stuck. This is what I have, what do I do next?
|
Author: | AsianSensation [ Sun Mar 20, 2005 12:24 pm ] | ||
Post subject: | |||
it looks like you are first getting a number from the textfile, and this number corresponds to the number of lines/items in your file. Now all you have to do is run a for loop. Since you know how many items you are getting, it's not that hard.
|
Author: | gnarky [ Sun Mar 20, 2005 7:14 pm ] |
Post subject: | |
Yes! Ive completed my goal! Thanks everyone a lot for all of your help. Id give bits, but I dont have many. Thanks |