struct

Writing different structs to a file in C++? [closed]

筅森魡賤 提交于 2019-12-24 12:43:10
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I need a way to write structures of three different kinds to a binary file, which later has to be searched. (As in, for example, struct A has two fields, an int and a char; struct B has int and a long; I need to output all structures whose int equals the one given from keyboard). I understand how

How to Pop different types of Structs from a Stack

余生长醉 提交于 2019-12-24 12:34:39
问题 I have a stack that contains two types of struct. Struct Stud and Struct Prof. When I want to push something I created two Push functions for both structs. Although I would like it to be with one function but its ok I can bear with it. Now to Pop. If I want to Pop a student from the Stack, do I have to make a Pop function specifically for Students only? The same with Professors? How can I store the item if I don't know what type is it? What type must the element be, to store the item there?

Get member definition name given member definition address?

那年仲夏 提交于 2019-12-24 12:16:57
问题 Given an address to a structs member variable, is it possible to get the name of the member variable and store it in a character pointer? #include <stdio.h> struct struct_name{ char char_1; char char_2; }; int main(){ struct custom_struct struct_name; char *member_name = NULL; member_name = getName( struct_name + 1); // member_name = "char_2" return 0; } 回答1: AFAIK C doesn't natively support reflecton. So if you really want it, you need to do it yourself. One way you can do it (how acceptable

Converting bit field to byte array

可紊 提交于 2019-12-24 11:35:48
问题 I have some mpeg ts bitfields, for example transport stream package: struct ts_package_header_s { unsigned int continuity_counter :4; unsigned int adaptation_field_control :2; unsigned int transport_scrambling_control :2; unsigned int PID :13; unsigned int transport_priority :1; unsigned int payload_unit_start_indicator :1; unsigned int transport_error_indicator :1; unsigned int sync_byte :8; }; struct ts_package_s { struct ts_package_header_s ts_header; unsigned char ts_body[TS_BODY]; };

Scanf skips second line of input, always

让人想犯罪 __ 提交于 2019-12-24 11:35:14
问题 I'm trying to read lines of text data, and store them in a linked list. Input data looks something like this: David Copperfield Charles Dickens 4250 24.95 32.95 10 6 END_DATA The way I read the data is to first read the first line to see if it is END_DATA. If it's not, then I pass the first line into a function which creates a linked list Node with the book data inside. For some reason, scanf does not read the second line after I pass the first line to the function. When I try to print the

Creating dynamic vector on predefined struct

自闭症网瘾萝莉.ら 提交于 2019-12-24 10:59:47
问题 I have a predefined struct to use : typedef struct somestruct_s { int s; union { unsigned char *ptr; unsigned char l_ptr[sizeof(char *)]; }; }somestruct_t, *somestruct; It contains union to reduce memory usage. I know the size can vary due to m32 and m64 compilation (pointer size). My question is how to "use" that struct for my precise assignment. The purpose of this struct is to implement basic bit operations, the s variable contains the size of the bitmap in bytes. If the bitmap can fit

Mapping C structure to an XML element

旧城冷巷雨未停 提交于 2019-12-24 10:58:59
问题 Suppose I have a structure in C or C++, such as: struct ConfigurableElement { int ID; char* strName; long prop1; long prop2; ... }; I would like to load/save it to/from the following XML element: <ConfigurableElement ID="1" strName="namedElem" prop1="2" prop2="3" ... /> Such a mapping can be trivially done in Java/C# or any other language with run-time reflection for the matter. Can it be done in any non-tedious way in C++ with macros/template trickery? Bonus points for handling nested

MarshalJSON a type with an embedded type ends up as {} instead of the value

余生颓废 提交于 2019-12-24 10:56:17
问题 To interact with swagger, I needed to make a custom BigInt struct which does nothing more than wrap around go's big.Int . type BigInt struct { big.Int } ... type SpendTx struct { SenderID string `json:"sender_id,omitempty"` RecipientID string `json:"recipient_id,omitempty"` Amount utils.BigInt `json:"amount,omitempty"` Fee utils.BigInt `json:"fee,omitempty"` Payload string `json:"payload,omitempty"` TTL uint64 `json:"ttl,omitempty"` Nonce uint64 `json:"nonce,omitempty"` } func (t SpendTx)

typedef struct in header and dereference pointer to incomplete type

十年热恋 提交于 2019-12-24 10:55:52
问题 I'm quite rusty in C, but I think I'm having issues understanding the proper usage of using typedef s in headers, defining the actual struct's structure in the implementation file, and then using the struct in a third file. I wrote a queue data-structure that has a type defined as such: typedef struct queue { int count; qnode_t *head; qnode_t *tail; } queue_t; Where qnode_t is a struct that's only used within the queue's implementation file. Within my header I have this: typedef struct queue

How to read and data from text file to array structure in c programming?

妖精的绣舞 提交于 2019-12-24 10:52:10
问题 By using a function, the program should read the data from each line as information about a car’s name, cargo type, weight (full), length, required horsepower to pull that car type, and number of cars of that type. The data must be stored in an array of structures as it is being read from the file then displayed in console. The strsub() function must be used. Unfortunately the data from the text file isn't printing to the console. I think the problem may lie in my use of pointers, but I've