Answers.Body: <p>Most probably the problem is that the array is declared, but not initialized. The program does not know how much memory to allocate for this specific array and therefore there is no available storage in RAM for it.</p>
  
  <p>To solve this, try initializing your array. You can either provide the starting dimensions during declaration, like in the last example <a href="http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/arrays.html" rel="nofollow noreferrer">here.</a>
  Which in your case would look like this:</p>
  
  <pre><code>char road[10][9];
  </code></pre>
  
  <p>And it will result in an array the given size, filled with zeroes.</p>
  
  <p>Or use a function call to do the same if you have specific (not 0) initial values: <a href="http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/group___array_functions_ga49d48de55d817e96ed132eadc21260eb.html" rel="nofollow noreferrer">http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/group___array_functions_ga49d48de55d817e96ed132eadc21260eb.html</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T12:08:58.357Z
Answers.Text: it does look like to work.. Problem is, when i try to run 
  `TextOut(0,LCD_LINE1,road[1])` it doesn't output anything...
Answers.UserDisplayName: test
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T12:16:15.640Z
Answers.Text: So i am bit unsure if it actually do what it is supposed to do?
Answers.UserDisplayName: test
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T12:16:36.190Z
Answers.Text: I guess that is because `road` is a 2D array, so `road[1]` is still an array, not a string what TextOut expects.
Answers.UserDisplayName: zovits
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T12:32:55.713Z
Answers.Text: how would you convert a char array into a string using the nxc syntax. Doesn't seem to be any function capable of doing so..
Answers.UserDisplayName: test
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T13:33:41.537Z
Answers.Text: You could use the `fgets`function to read string values from your file: http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/group__cstdio_a_p_i_ga66a374bc9be9c7172e77d7fb314aa5c2.html Keep in mind though that `fgets` reads until it hits an end of line or an end of file character, so you will need to break your input file to lines or read the whole file as a string and then perform slicing.
Answers.UserDisplayName: zovits
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T16:24:42.180Z
Answers.Text: I have to store in a 2d Char array, at it makes it easier to now the position of the robot based on the char array.
Answers.UserDisplayName: test
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2015-09-22T11:37:52.763Z
Answers.LastActivityDate: 2020-05-01T23:19:17.677Z
Answers.LastEditDate: 2020-05-01T23:19:17.677Z
Answers.UserDisplayName: zovits
Body: <p>I tried to upload this program to my NXT, but for some reason I am not able to run it properly as it is always terminated with the message <code>File error!</code>. No idea why. </p>
  
  <p>I am trying to read a .txt file into a <code>char road[][]</code>. I think it is where I insert the value into my 2d array where things go wrong. </p>
  
  <pre><code>#import "road.txt" 
  
  task main()
  {   
      FileOpenType road_txt;
      file.Filename = "road.txt";
      SysFileOpenRead(road_txt); 
      char road[][]; 
      while(road_txt.Result == NO_ERR)
      {
         for( int i = 0; i &lt; 10; i++ )
         {
  
           for(int j = 0 ; j &lt; 09 ; j++)
           {  
              char temps = fgetc(road_txt.FileHandle);
              if(temps != '\n')
              {
                  road[i][j] = temps;
  
              }
           }
  
         }    
  
      }
  
  }   
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-22T11:15:44.167Z
Comments.Text: What steps did you take to diagnose the error? E.g. are you sure the file is there? Are you sure it has the correct content? Have you tried adding debug messages to find the exact line where failure occurs?
Comments.UserDisplayName: zovits
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-22T11:28:20.200Z
Comments.Text: All debug messages chrashed after `road[i][j] = temps`
  
  The .txt file is on the nxt
Comments.UserDisplayName: test
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-23T10:22:37.313Z
Comments.Text: Don't forget that `#import "road.txt"` [creates an implicit byte array](http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/import.html) named after the filename (in this case `road`) when it loads the file if you don't specify a name for the array - you're then redefining that 1d array into a 2d char array - that might be the issue - try removing the `#import` directive.
Comments.UserDisplayName: Zhaph - Ben Duguid
Tags: <nxt><nxc>
Title: "File error!" appears on NXT, but why?
UserDisplayName: test
ThreadText: # "File error!" appears on NXT, but why?
  
  (Asked by: username_0 on 2015-09-22)
  
  I tried to upload this program to my NXT, but for some reason I am not able to run it properly as it is always terminated with the message File error!. No idea why. 
  I am trying to read a .txt file into a char road[][]. I think it is where I insert the value into my 2d array where things go wrong. 
  #import "road.txt" 
  
  task main()
  {   
      FileOpenType road_txt;
      file.Filename = "road.txt";
      SysFileOpenRead(road_txt); 
      char road[][]; 
      while(road_txt.Result == NO_ERR)
      {
         for( int i = 0; i < 10; i++ )
         {
  
           for(int j = 0 ; j < 09 ; j++)
           {  
              char temps = fgetc(road_txt.FileHandle);
              if(temps != '\n')
              {
                  road[i][j] = temps;
  
              }
           }
  
         }    
  
      }
  
  }
  
  **Tags:** nxt, nxc
  > **Comments:**
  > **username_1**: What steps did you take to diagnose the error? E.g. are you sure the file is there? Are you sure it has the correct content? Have you tried adding debug messages to find the exact line where failure occurs?  
  > **username_0**: All debug messages chrashed after `road[i][j] = temps`  The .txt file is on the nxt  
  > **username_2**: Don't forget that `#import "road.txt"` [creates an implicit byte array](http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/import.html) named after the filename (in this case `road`) when it loads the file if you don't specify a name for the array - you're then redefining that 1d array into a 2d char array - that might be the issue - try removing the `#import` directive.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-09-22. Score: 1
  
  Most probably the problem is that the array is declared, but not initialized. The program does not know how much memory to allocate for this specific array and therefore there is no available storage in RAM for it.
  To solve this, try initializing your array. You can either provide the starting dimensions during declaration, like in the last example here.
  Which in your case would look like this:
  char road[10][9];
  
  And it will result in an array the given size, filled with zeroes.
  Or use a function call to do the same if you have specific (not 0) initial values: http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/group___array_functions_ga49d48de55d817e96ed132eadc21260eb.html
  
  > **Comments:**
  > **username_0**: it does look like to work.. Problem is, when i try to run  `TextOut(0,LCD_LINE1,road[1])` it doesn't output anything...  
  > **username_0**: So i am bit unsure if it actually do what it is supposed to do?  
  > **username_1**: I guess that is because `road` is a 2D array, so `road[1]` is still an array, not a string what TextOut expects.  
  > **username_0**: how would you convert a char array into a string using the nxc syntax. Doesn't seem to be any function capable of doing so..  
  > **username_1**: You could use the `fgets`function to read string values from your file: http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/group__cstdio_a_p_i_ga66a374bc9be9c7172e77d7fb314aa5c2.html Keep in mind though that `fgets` reads until it hits an end of line or an end of file character, so you will need to break your input file to lines or read the whole file as a string and then perform slicing.  
  > **username_0**: I have to store in a 2d Char array, at it makes it easier to now the position of the robot based on the char array.  
  
  ---
  
  