refuses to open file

rbtwms at digitalpath.net rbtwms at digitalpath.net
Wed Apr 17 16:48:38 PDT 2013


Is it really "defile" that gets printed up there, or is that another
typo? I highly recommend that you provide a complete program for us to try.
spell checker got away from me.

This time it seems to be complaining about a space *after* the file
name! (?)
makes no difference.

I have a vague recollection that forward slashes work with file names
even under Windows.
makes no deference.

That doesn't look right: char is a UTF-8 code unit. Unless you are sure
that the file contains UTF-8, I recommend you use something else, e.g.
ubyte.
It' a pure ascii file.

Do you intend to ignore that read? The data will be overwritten by the
following rawRead.
Yes it is a leader for the data file, all records same length.

You are doing that because you are sure that there is a valid Unicode
character there? (Although I am not sure how it is related to the problem.)
Yes each record that has data in it starts with hex01 the first 20 bytes is
non ascii junk.

The thing is the program was working until I tried to add the command line
args.
The data file is quite large 01/04/2013  10:04 AM         1,909,000 KEY

complete source follows:

// Equipment file display
import std.stdio, std.string, std.conv, std.algorithm;
struct equipment {
  char[20] header;
  char[8] sysnum;
  char[2] type;
  char[5] eznum;
  char[12] manfac;
  char[3] ver;
  char[10] mod;
  char[2] junk1; // info we dont need
  char[5] price; // price per play
  char[25] name;
  char[15] sernun;
  char[10] opnum;
  char[40] junk2; // more info we dont need
  char[25] purchfrom;
  char[10] purchdate;
  char[11] cost;
  char status;
  char[4] locnum;
  char[4] junk3;
  char[30] locname;
  char[382] junk4;
  char[15] loccity;
  char[2] state;
  char[5220] junk5;
  }


void main (string[] args)
{
	
  File efile;
  equipment eqip;
  int type;
  efile = File("l:\\filepro\\mvmmach\\key");
/*
writeln("args.length = ", args.length);
	switch (args.length){
  	case 1:
    	efile = File ((to!string(" l:\\filepro\\mvammach\\key ")));
		  writefln("efile name is %s", efile);	
    	break;
    case 2:
      efile = File(args[1]);
      writefln("efile name is %s", efile);
      break;
    case 3:
    	type = to!int( args[2] );
      break;
    default:
      break;   	
     }

writefln("efile name is %s", efile);  	    	
  char[4600] buf;
  string[int] list;
	efile.rawRead(buf);
  while(efile.rawRead(buf)){
    if(buf[0] != 0x01) continue;
    string c = to!string (buf[107..111]);
    if (c == "    ") break;
    int z = to!int(c);
    string s = to!string(buf[67..92]);
    list[z] = s;
    }
  int numb[] = list.keys;
  sort (numb); 		//	{ return list[a] < list[b]; })(numb);
  	foreach(num; numb){
//    writef("num=[%d],type[%d]",num,type);
      if((num < type+999) && ( num > type)){
        writefln("Opnum = %s Name = %s", num, list[num] );
        }
      }
  }


More information about the Digitalmars-d-learn mailing list