I'm stuck on how to fix this. The program does not work, and I know why, but I don't know how to fix it.

It's not working because of this line:

Code:
     tempptr += ( tempptr->glen + sizeof(AMG) )   ;
The addition to tempptr is taking the value inside the parens on the right size and multiplying it times the size of the structure.

I've tried all sorts of casts, but nothing is working. Help!

The buffer array is a structure that is sent as input, built by another process. The first byte is a length of the name, then there is a fill byte, and then the name. I need to extract all three piece for an many times as there are entries.

Code:
#include <stdio.h>                                                   
#include <memory.h>                                                  
                                                                     
struct amg {                // a multi-group mapping                 
   unsigned char glen ;                                              
   unsigned char gprv ;                                              
            char gnam[0] ;                                           
} ;                                                                  
                                                                     
typedef struct amg AMG ;                                             
                                                                     
                                                                     
int main(void) {                                                     
                                                                     
   int i ;                                                           
   int increment ;                                                   
   char gname[9] ;                                                   
   char * ptr ;                                                      
                                                                     
   // 3 group structures.   L=6, 0, Name=A23456                      
   //                       L=4, 0, Name=SYS1                        
   //                       L=5, 0, Name=B2345                       
                                                                     
   unsigned char buffer[] = { 6 , 0 , 'A', '2', '3', '4', '5', '6' , 
                              4 , 0 , 'S', 'Y', 'S', '1',            
                              5 , 0 , 'B', '2', '3', '4', '5' } ;    
                                                                     
   int grpcnt = 3 ;                                                  
                                                                     
                                                                     
   AMG * tempptr ;                                                   
                                                                     
   tempptr = (AMG *) buffer ;                                        
                                                                     
   for (i = 0 ; i < grpcnt ; i++ ) {                                 
                                                                     
      printf("tempptr=%08p, buffer@=%08p\n", tempptr, buffer ) ;     
                                                                     
      memset(gname, 0x00, (unsigned) sizeof(gname)) ;                
                                                                     
      ptr = (char *) tempptr->gnam ;                                 
                                                                     
      strncpy(gname, ptr , tempptr->glen) ;                          
                                                                     
      printf("GrpLen=%d, GrpName=>%.8s<\n", tempptr->glen, gname) ;  
                                                                     
      increment = tempptr->glen + sizeof(AMG) ;                      
      printf("Increment is %d\n", increment) ;                       
                                                                     
      tempptr += ( tempptr->glen + sizeof(AMG) )   ;                 
   }                                                                 
                                                                     
   return 0 ;                                                        
}