Oh no, I suppose it wasn't apparent. I guess since I wrote it I know exactly what it does and forgot it could be less forthcoming to others, so basically:
When you parse a file, the first thing you want to do is determine two basic things:
01. How many lines it has
02. How long each line is
You want this information so that you can scan through the contents of the file line by line. Rather than working with one long string, you could work with several much smaller strings and this is optimal whilst parsing a files contents. The way I did it was like so:
Code: Select all
for(h=0;h<strlen(buf);h++) //loop the length of buffer
{
if(buf[h]=='\n') //let me know when you find a newline
{
char line[256]={0}; //thanks, go ahead and make some space
cpos=chrpos(buf,'\n',cpos+1); //tell me where that newline is
substr(buf,npos,cpos-1,line); //thanks, now gather the string from start to newline
//variable (line) contains our string, so start manipulating it . . .
}
}
In my example above I was parsing a map file having a format similar to a command line switch:
blah -s 0110 -e 1001
halb -s 1001 -e 0110
In my program I must fulfill three requests:
01. the title of the line (owner of the args)
02. what lyes beyond the -s arg
03. what lyes beyond the -e arg
That's what I was doing with this code here:
Code: Select all
substr(line,0,strpos(line,".")+3,file);
substr(line,strpos(line,"-s")+2,7,pada);
substr(line,strpos(line,"-e")+2,7,padb);
I hope
this helps.
Free energy is indeed evil for it absorbs the light.