struct

how to write the character value from structure into the serial interface and convert into integer value?

点点圈 提交于 2019-12-31 06:01:07
问题 struct MemoryTag1; typedef struct MemoryTag1{ char a[8]= {'+','0','2','6','.','5','EA','\r'}; // setpoint temperature value char b[8]= {'-','0','2','4','.','5','EB','\r'}; char c[6]= {'+','0','2','0','EC','\r'}; }Memory1; // This is a message structure which I want to transfer over the serial interface (RS232) and later convert into integer value. please guide me in this. 回答1: Your syntax is a bit off - try this: // declare Memory1 struct type to hold data typedef struct MemoryTag1 { char a[9

Using C, to print out an array from textFile

醉酒当歌 提交于 2019-12-31 05:48:04
问题 I'm trying to create a code, which reads from textile, and then stores the data into memory, prints out to the screen so the user can read it, but it is still saved into the memory so you can use it for the rest of the program.. Here is the sample of the textile 75 nevermind nvm not much nm no problem np people ppl talk to you later ttyl because cuz i don't know idk as soon as possible asap yeah ya how are you hru you the list goes on, it has a total of 150 words, 151 lines if the first

Passing a struct with a byte array inside to a interop-ed method

亡梦爱人 提交于 2019-12-31 05:38:08
问题 I have a situation where I have to pass a struct to a C method (declared as extern in my C# file). This struct however is quite complicated. I already used successfully the approach with AllocHGlobal, but I would like to understand if is possible to make it works in this way, by only passing a reference to the struct. [StructLayout(LayoutKind.Sequential)] struct lgLcdBitmapHeader { public Formats Format; } [StructLayout(LayoutKind.Explicit)] struct lgLcdBitmap { [FieldOffset(0)] public

Write and load vector of structs in a binary file c++

a 夏天 提交于 2019-12-31 05:32:12
问题 I really need your help. I have the following structs in my code: struct Field{ char name[20]; int type; int length; }; struct Record{ vector<Field> structure; vector<string> info; }; What I want to do is to store a vector of my struct Record inside a binary file and to successfully load it back. The problem is that my struct has two vectors inside of it and they are causing me some trouble. Can you help me out? 回答1: I know it's a duplicate but meh.. I was bored. You basically just write

Conversion of C/C++ Struct To C#.Net CF WinCE

可紊 提交于 2019-12-31 05:00:49
问题 Hi I am trying to convert the C/C++ Strcut to C# C/C++ Struct looks like: typedef struct _NDISUIO_QUERY_OID { NDIS_OID Oid; PTCHAR ptcDeviceName; UCHAR Data[sizeof(ULONG)]; } NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID; My C# Struct is: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct _NDISUIO_QUERY_OID { public uint Oid; [MarshalAs(UnmanagedType.LPWStr)] public string ptcDeviceName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8*sizeof(uint))] public string Data;

C: Read from textfile into a struct array

ぃ、小莉子 提交于 2019-12-31 04:21:12
问题 The program I am making is supposed to read in numbers from a text file and save the total number of numbers, the average value of the numbers in a struct. I have a struct that looks like this: struct seriepost { int totnr; int outnr; float average; }; And the function (unfinished) looks like this: int read_data(FILE *tsin, struct seriepost serie[]) { int x = 0; float average = 0; float in_last = 0; while (!feof(tsin)) { while (fscanf(tsin, "%f", &in_last) != 0.0) { serie[x].totnr += 1; serie

Not receiving a seg fault when expected

旧时模样 提交于 2019-12-31 04:19:05
问题 I'm in the process of learning how to use pointers and structs in C. Naturally, I'm trying to deliberately break my code to further understand how the language works. Here is some test code that works as I expected it to work: #include <stdio.h> #include <stdlib.h> struct pair { int x; int y; }; typedef struct pair pair; void p_struct( pair ); //prototype int main( int argc, char** argv ) { pair *s_pair; int size, i; printf( "Enter the number of pair to make: " ); scanf( "%d", &size );

C Insert Element At Beginning of Linked List

跟風遠走 提交于 2019-12-31 03:56:09
问题 I have written a program in C that is designed to insert structures in an ascending order into a Linked List. The problem is that is is not inserting my two lowest values (1 and 2). This is because I don't currently have a working handler to check if the first value of the linked list is already greater than the given. Here is my function: struct PCB { struct PCB *Next_PCB ; int PID ; }; void insert_ordered (struct PCB *Head, struct PCB *Add) { tmp = Head; if (Head->PID == 0) { Head->PID =

C++ Assigning Values to POD Objects [duplicate]

送分小仙女□ 提交于 2019-12-31 03:53:27
问题 This question already has answers here : Correct way of initializing a struct in a class constructor (5 answers) Closed 5 years ago . So I read about Plain Old Data classes (POD) , and decided to make my structs POD to hold data. For example, I have struct MyClass { int ID; int age; double height; char[8] Name; }; Obviously, to assign values to the struct, I can do this: MyClass.ID = 1; MyClass.age = 20; ... But is there anyway to assign raw data, WITHOUT knowing the name of each field? For

Store information/reference about structure

大城市里の小女人 提交于 2019-12-31 03:13:13
问题 I am looking for a way to store information which struct a function should use. Each struct corresponds to certain database table. type Record struct { TableName string PrimaryKey string //XormStruct // how can I store User or Post here? XormStruct2 interface{} // see I have tried below XormStruct3 reflect.Type // see I have tried below } var posts []Post var ListOfTables [...]Record { {"User", "id", User}, //{"Post", "post_id", Post}, {"Post", "post_id", posts, reflect.TypeOf([]Post{})}, } /