473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

print struct structure

It has been a long while since I did any C programming. I am trying to read the utmp.h header on RHEL vs 5 but I am getting a little lost with the branching. I wanted to write a simple program that would create a struct of type utmp and then would print out each element name and type. Such as, "the first element is called ut_type and is an integer." I have:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. # include <utmp.h>
  3. int main(int argc, char *argv[]) {
  4. struct utmp ut;
  5. int size;
  6. size = sizeof(ut);
  7. printf ("Size = %d\n", size);
  8. }
This gives me the size of the structure, but I'd like to find each element. Is this possible?

Thanks!

Brad
Nov 18 '08 #1
2 2444
JosAH
11,448 Expert 8TB
This gives me the size of the structure, but I'd like to find each element. Is this possible?
Nope, not in C; it's a pure compiled language and names only have a meaning
during compile time. During runtime an actual struct is just a sequence of bytes
(chars) that you treat as a struct, i.e. the bare metal doesn't care less.

kind regards,

Jos
Nov 18 '08 #2
newb16
687 512MB
There is no reflection in c(++). You need to read this header file with your own eyes.
Nov 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mordac | last post by:
Hello, I was wondering if I could get some opinions on how best to handle printing in a max heap data structure. Right now my heap struct looks as thus: typedef struct heapStruct { int*...
10
by: Joe M | last post by:
I was wondering if someone could lend me a hand with a C# problem I am having I am trying to use the “setPrinter” api to change the duplex setting (under printing preferences on printer...
5
by: Bill Pursell | last post by:
Suppose I have a structure with many members, and I pass a pointer to that structure to a function. I'd like the prototype of the function to specify that it will only be changing certain members...
0
by: hoderbob | last post by:
I need to find a way to catch the parameters entered in the Print Dialog box of any Windows application and pull the number of copies the user selected. I know most printers allow the driver to...
3
by: rwise5 | last post by:
I have been tasked with finishing the following C program. I need to develop the sort by birthday function and the print grade function. I have been working on the print function for the last week...
13
by: katysei | last post by:
I have to print several large structs to print the screen. I was wondering if thers a tool to do so automaticly struct A { int i; char * s; }
22
by: joshc | last post by:
In an interview for an embedded software position recently I was asked to write code, in C, for printing the contents of a linked list backwards. After a few minutes I came up with the recursive...
8
by: cman | last post by:
What does this kind of typedef accomplish? typedef struct { unsigned long pte_low; } pte_t; typedef struct { unsigned long pgd; } pgd_t; typedef struct { unsigned long pgprot; } pgprot_t I am...
6
by: arnuld | last post by:
I am unable to add anything to this structI can't understand why I am getting a Segfault: #include <stdio.h> struct macd {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.