0

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;
}
2
Contributors
1
Reply
15
Views
2 Years
Discussion Span
Last Post by Schol-R-LEA
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.