Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File I/O
#1
Could someone tell me how I would get info from a file named "board.brd"? Ok, better explanation. I have a file named "board.brd" that has this in it.

10,10
0,0,0,0,0,0,0,0,0,0
0,1,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,1,0
0,0,0,0,0,0,0,0,0,0

How would I read the contents from this file into a multidimensional array by using the width and height shown at the top of the file (10,10)? Tell me if this is confusing.
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Reply
#2
Code:
open "board.brd" for input as #1
input #1, dim1, dim2
dim board(dim1, dim2)

for dimen1 = 1 to ubound(board, 1)
  for dimen2 = 1 to ubound(board, 2)
    input #1, board(dimen1, dimen2)
  next
next

for dimen1 = 1 to ubound(board, 1)
  for dimen2 = 1 to ubound(board, 2)
    print board(dimen1,dimen2);
  next
  print
next
close #1
sleep

The printing is just a test to see if it worked.
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)