NXC: runtime error using SysListFiles

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

NXC: runtime error using SysListFiles

Post by HaWe »

I get a runtime error (File Error -1) using this code - why?

Code: Select all

    char LCDline[]={56,48,40,32,24,16,8,0};

    task main()
    {
      int i=1, j=1;
      ListFilesType args;
      args.Pattern = "*.rxe";
      SysListFiles(args);
      while (args.Result == NO_ERR && ArrayLen(args.FileList) > 0)
      {
        TextOut(0, LCDline[i], args.FileList[j]);
        if(i<7) i++;
        j++;
      }

      while(true);
    }

spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC: runtime error using SysListFiles

Post by spillerrec »

You have a never ending loop, yet you increment the array position for each time so it will obviously end in an access violation error.
Changing the "0" to "j" in the following line seems to have fixed it:

Code: Select all

while (args.Result == NO_ERR && ArrayLen(args.FileList) > 0)
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: runtime error using SysListFiles

Post by HaWe »

thank you very much, now I finally understand the sence of the 2nd while argument!
I changed the code, now it's fine :)

Code: Select all

char LCDline[]={56,48,40,32,24,16,8,0};

task main()
{
  int i=0, j=0;
  ListFilesType args;
  args.Pattern = "*.*";
  SysListFiles(args);
  while (args.Result == NO_ERR && j < ArrayLen(args.FileList))
  {
    TextOut(0, LCDline[i], args.FileList[j]);
    if(i==7) {
      i=0;
      Wait(500);
      ClearScreen();
    }
    i++;
    j++;
  }
   while(true);
}
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 2 guests