sscanf problem,

David Medlock noone at nowhere.com
Wed Jul 5 04:22:02 PDT 2006


DMINATOR wrote:
> Hi
> 
> I have a little strange problem, probably I am doing something wrong.
> 
> I am writing a small parser for an 3d .OBJ format. I am using sscanf for
> parsing. Most of the results are correct, except one place.
> 
> Here is the part of input text file:
> 
> g object_1
> f 12/934/12 228/1/228 231/936/231
> f 228/1/228 72/75/72 229/935/229
> f 231/936/231 229/935/229 75/937/75
> f 227/2/227 231/936/231 230/10/230
> f 72/75/72 695/960/695 1346/3/1346
> f 695/960/695 2/1352/2 1345/1328/1345
> f 1346/3/1346 1345/1328/1345 73/938/73
> f 229/935/229 1346/3/1346 233/939/233
> f 654/7/654 232/6/232 75/937/75
> f 233/939/233 236/4/236 654/7/654
> f 75/937/75 233/939/233 654/7/654
> f 644/5/644 236/4/236 233/939/233
> f 73/938/73 234/1340/234 644/5/644
> f 233/939/233 73/938/73 644/5/644
> f 236/4/236 644/5/644 647/940/647
> f 644/5/644 234/1340/234 645/859/645
> f 647/940/647 645/859/645 646/234/646
> f 643/8/643 647/940/647 235/1032/235
> f 232/6/232 654/7/654 656/941/656
> f 654/7/654 236/4/236 643/8/643
> f 656/941/656 643/8/643 655/231/655
> f 653/942/653 656/941/656 655/231/655
> f 666/15/666 242/943/242 71/9/71
> f 230/10/230 244/16/244 666/15/666
> f 71/9/71 230/10/230 666/15/666
> f 658/12/658 244/16/244 230/10/230
> f 75/937/75 232/6/232 658/12/658
> f 230/10/230 75/937/75 658/12/658
> f 244/16/244 658/12/658 660/11/660
> 
> 
> --------------------------
> Here is the code I use for reading that :
> 

Here is my function for reading OBJ faces:

alias char[] string;

void read_face( string data, Group target )
{
   if ( target is null ) throw new Exception("Face data with no group 
found!" );
   string[] info = split( data );
   if ( info.length != 3 ) throw new Exception("Malformed face data:" ~ 
data );

   face* f = target.addface();
   void  add( int which, string vi, string ci )
   {
     f.v[which] = atoi(vi)-1;
     f.c[which] = atoi(ci)-1;
   }

   void add_info( int index )
   {
     string s = info[index];
     string[] arr = split( s, "/" );
     if ( arr.length<2 ) throw new Exception("Malformed face data 
group:"~ s );
     else add( index, arr[0], arr[1] );
   }

   add_info( 0 );
   add_info( 1 );
   add_info( 2 );
}

-DavidM




More information about the Digitalmars-d-learn mailing list