Hi guys,
I want to access the element of structure from structure pointer using indexing for below code snippet.
apart from this I also would like to know is there any way to find the type of member variable of structure on run time.

#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include<stdint.h>

typedef struct Node{
  uint32_t var1;
  uint16_t var2;
  uint32_t  var3;
  uint8_t *var4;
  uint8_t  var5[257];

}node_t;

void initialize_field(node_t *field_val )
{
    field_val = (node_t*)malloc(sizeof(node_t));
    assert(field_val != NULL);
    field_val->var1=0x22;
    field_val->var2= 2023;
    field_val->var3 =8132014;
    strcpy(field_val->var4,"RRAA:1001");
    strcpy(field_val->var5,"ABC");


}

int main()
{
node_t *field_val=NULL;
initialize_field(field_val);
//field_val[index]   doesn't seems to be possible  
return 1;
}

No, it isn't possible in C (it can be done in C++, using operator overloading, but it would require you to write the overloaded operator function). The solution is to write a function that acts similarly, by walking through the list a fixed number of nodes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.