I am interested in printing the structure fields .
Typedef struct { UINT32 thread_id; BOOL is_valid; }T_THREAD;
Is there a way in "C" language to print the contents of a structure, something like
ex: print (T_THREAD)
and output should be like
Contents of a structure T_THREAD are thread_id is_valid
It's often necessary to print out struct values to the console for the purpose of debugging. If you use the go-to fmt. Println method, it only prints the values of the struct without the field names. Another option is to use json.
Instead, you should pass the address of the first character of the string which is: scanf("%s %d", &(tempname[0]), &temptel); or more simply: scanf("%s %d", tempname, &temptel);
Syntax to Define a Structure in CstructName: This is the name of the structure which is specified after the keyword struct. data_Type: The data type indicates the type of the data members of the structure. A structure can have data members of different data types.
Structures (also called structs) are a way to group several related variables into one place. Each variable in the structure is known as a member of the structure. Unlike an array, a structure can contain many different data types (int, float, char, etc.).
What you're looking for is reflection. Java and other virtual languages has reflection so you can print out the variable names and function names for any given class. Because the compiler builds these reflection functions automatically.
C does not have reflection. You must do everything manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With