Computer Science Canada

getting certian parts of files

Author:  Blade [ Thu Mar 20, 2003 5:24 pm ]
Post subject:  getting certian parts of files

ok, i have to do this program, that gets only one part of a file...
i have 2 coloms listed
(underscores are spaces)

and so on
how would i get only the second colomn of numbers to use in my program? i need the second colomn to square root it and add it to a third colomn. (i know the square root is the first colomn, but thats what i need to do)

Author:  Tony [ Thu Mar 20, 2003 5:28 pm ]
Post subject: 

well the easiest way is to read both columns and just ignore the first one. Otherwise you'd have to figure out random-access (using read/write instead of put/get... there're some working programs with that posted on the board, you just have to look).

get word1 %ignore
put word1 %rewrite to new file
get word2 %2nd column
put word2 %rewrite
put word2**2 %calculate 3rd column

something like that

Author:  Blade [ Thu Mar 20, 2003 5:31 pm ]
Post subject: 

ah i see... i never really though of that Smile <-- dumbass

but, i cant work with a string... i need to read an integer.. but it doesnt let me read integers from a file

Author:  Tony [ Thu Mar 20, 2003 5:40 pm ]
Post subject: 

strange... you should be able to read integers... unless you got more then 1 spaces between columns Confused

you can use get skip then to get all the spaces in between.

Author:  Blade [ Thu Mar 20, 2003 6:07 pm ]
Post subject: 

YAY it worked... i have one more question though...

how would i replace something in the file...

i have a list of months.. i need to delete april out, and replace it with avril

Author:  Tony [ Thu Mar 20, 2003 6:50 pm ]
Post subject: 

well you usually read from 1 file and write to a temporary one. So

get month

if month = "april" then
put "whatever"
put month
end if

that type of thing

Author:  Blade [ Thu Mar 20, 2003 7:52 pm ]
Post subject: 

so, i would read the file, then rewrite the whole thing with avril instead of april

Author:  Asok [ Thu Mar 20, 2003 9:06 pm ]
Post subject: 

right because you can write over it.

Author:  Dan [ Thu Mar 20, 2003 9:07 pm ]
Post subject: 

that or use the read/wire comands wich are hread to figer out and use.