Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
this program eliminates repeated elements of a file of text
#1
'lrcvs 14.09.08

'this program eliminates repeated elements of the original file called: "a"
'........ and enter the correct elements in the file destination called "b"

'este programa elimina los elementos repetidos del fichero origen llamado: "a"
'........ y escribe los elementos correctos en el fichero destino llamado: "b"

cls
open "i", #1, "a.txt"
10 :
if eof(1) then goto 20
input #1, a$
open "i", #2, "b.txt"
15 :
if eof(2) then goto 30
input #2, b$

'here we comparisons
'aqui hacemos las comparaciones
if a$ = b$ then close (2): goto 10

goto 15
print a$
goto 10
20 :
close (1)
end

30 :
'here we write the unique elements
'aqui escribimos los elementos unicos
close (2)
open "a", #2, "b.txt"
print #2, a$
close (2)
goto 10



Reply
#2
(09-14-2008, 01:31 PM)lrcvs link Wrote:'lrcvs 14.09.08

'this program eliminates repeated elements of the original file called: "a"
'........ and enter the correct elements in the file destination called "b"

'este programa elimina los elementos repetidos del fichero origen llamado: "a"
'........ y escribe los elementos correctos en el fichero destino llamado: "b"

cls
open "i", #1, "a.txt"

10 :
if eof(1) then goto 20
input #1, a$
open "i", #2, "b.txt"

15 :
if eof(2) then goto 30
input #2, b$

'here we comparisons
'aqui hacemos las comparaciones
if a$ = b$ then close (2): goto 10
goto 15
print a$
goto 10

20 :
close (1)
end

30 :
'here we write the unique elements
'aqui escribimos los elementos unicos
close (2)
open "a", #2, "b.txt"
print #2, a$
close (2)
goto 10

Luis, I have some questions for you:

1. As far as I know, to close a particular file, say b.txt, that was opened as #2, the syntax is:
CLOSE #2.
You use
CLOSE (2).
The only thing I can think of is that QB would interpret this as
CLOSE
which would close ALL open files.

2. Your program compares the elements of two files, in order of occurrance.  So,if you had, in a.txt, the values 1, 2, 3, and in b.txt, the values , 2, 3, 4, your program would compare 1 in a.txt with 2 in b.txt, and decide they are different. .  .but, both files contain a 2.  Shouldn't your program compare the first element of a.txt with all elements of b.txt, and so on. to really catch the elements that are common to both files?

The above is as far as I have gone into trying to understand your program.

By the way, if you are still using an electronic translator, it seems to bedoing a very good job this time.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#3
Hi, Ralph!

This is the theory of process...

Init values:
File : A = a,z,c,a,h,a,b,e,f....
File : B = Ø

Process:

1:
Read A
End A? : Y >>> Close A >>> End program
End A? : N >>> Read B(x)
If A(x) = B(x) : N >>> Open B >>> Write A(x) in B >>> Close B >>> Goto 1
If A(x) = B(x) : Y >>> Goto 1

End process


End values:
File : A = a,z,c,a,h,a,b,e,f....
File : B = a,z,c,h,e,f

Greetings from Spain!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)