zeiger-zeiger frage



  • Morgen,

    hab eine zeiger-zeiger frage:

    typedef struct {
    
       unsigned char Type; 
    
    }TypeStruct; 
    
    void test (unsigned char **ptr, unsigned char type)
    {
    
     TypeStruct *pValue = (TypeStruct *)NULL; 
    
      pValue = (TypeStruct *) *ptr; 
      pValue->Type = (unsigned char) type; 
    
      *ptr++; 
    
    }
    

    Der Zeiger ptr zeigt auf ein Array, das ich mit Werten befüllen möchte - einer von diesen Werten ist type. Leider steht bis jetzt der Type-Wert noch nicht im Array drinnen...

    pValue->Type = (unsigned char) type;
    

    Irgendwie greif ich hier scheinbar noch nicht richtig zu...

    gruß
    martin



  • #define E 10
    
    typedef struct
    {
       unsigned char Type;
    }TypeStruct;
    
    void test ( unsigned char* ptr, unsigned char type )
    {
    	*ptr = type;
    }
    
    void show( TypeStruct* TS )
    {
    	int i;
    	for ( i=0; i<E; i++ )
    		printf("%d\n", TS[i].Type, TS[i].Type );
    
    	while( TS->Type < E )
    		printf("%d\n", (TS++)->Type );
    }
    
    int main()
    {
     unsigned char i;
     TypeStruct types[E];
     for ( i=0; i<E; i++ )
    	test ( &types[i].Type, i );
     show ( types );
    }
    

Anmelden zum Antworten