user6211903
user6211903

Reputation: 11

qbasic what is the difference between open "file.dat" for input as #1 or input as #2

Now i am on grade 10 and i am learning about open"file.dat" for input/output as #n once have a look at my program

cls

open "samrat.dat" for output as #1

input "enter your name";n$

write #1,n$

close #1

end

so with this program i save my name to the file now i use output as #n to print this number. have a look at my next program

cls

open "samrat.dat" for input as #1

input #1,n$

print n$

close #1

end

so this program will print my or user name. but one thing is confusing me. if i will use open "samrat.dat" for input as #5 and change the #1 into #5 in all the places the output is same. I dont quite understand how it works. if #1 is same as #1000 what is the need of other number. please tell me

Upvotes: 1

Views: 350

Answers (1)

BdR
BdR

Reputation: 3048

You're right, your program will work as long as you use the same filenumber on all the places. The filenumber is just a token to tell the different files appart in your program.

It is possible for a program to access more than one file at the same time. For example you could read from one file, process the input, and then write it to another file.

OPEN infile$ FOR INPUT AS #1
OPEN outfile$ FOR OUTPUT AS #2
INPUT #1, A$
A$ = UCASE$(A$)
PRINT #2, A$
'etc.

Upvotes: 2

Related Questions