Page 1 of 1

NXC: runtime error using SysListFiles

Posted: 13 Feb 2011, 13:31
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);
    }


Re: NXC: runtime error using SysListFiles

Posted: 13 Feb 2011, 16:48
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)

Re: NXC: runtime error using SysListFiles

Posted: 13 Feb 2011, 17:21
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);
}