2 Replies - 290 Views - Last Post: 05 October 2012 - 07:15 AM Rate Topic: -----

#1 mumbot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-October 12

[Question] Reading Int32[,]

Posted 04 October 2012 - 07:41 PM

Hi C# coders i am having a problem reading some int values from a text file called SD_ENGINE_gui.txt

i want it so if you change the code bellow in the text file it will be applied in the script

 Int32[,] level ={
                        {w, w, w, w, w, w, w, w, w, w, w, w, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, f, f, f, w},
                        {w, w, w, w, w, w, w, w, w, w, w, w, w},
                           };


i have tried many ways but non seem to work

 try
            {
                using (StreamReader sr = new StreamReader(SD_ENGINE.gui))
                {
                    level = sr.Read();
                    Console.WriteLine(level);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(SD_ENGINE.ERROR);
                Console.WriteLine(e.Message);
            }


Also 1 thing i forgot to add w = 1 and f = 0

Is This A Good Question/Topic? 0
  • +

Replies To: [Question] Reading Int32[,]

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3177
  • View blog
  • Posts: 9,632
  • Joined: 05-May 12

Re: [Question] Reading Int32[,]

Posted 04 October 2012 - 09:52 PM

If level is a 2 dimensional array, then you'll have to access elements of the array by using level[row,col] where row and col indicate which row and column needs to be either read or written.

I suggest that you first become comfortable dealing with 1 dimensional arrays first before moving up to dealing with 2 dimensional arrays.
Was This Post Helpful? 0
  • +
  • -

#3 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4314
  • View blog
  • Posts: 7,472
  • Joined: 08-June 10

Re: [Question] Reading Int32[,]

Posted 05 October 2012 - 07:15 AM

Another part of your problem is that StreamReader.Read just reads one character at a time and returns it as an int. That doesn't mean that that it reads integers from the file, it reads the ASCII representation of each character.

Which basically means you're trying to assign one character to a two dimensional array. That won't work at all.

To really help you, we'd need to actually see your input file.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1