structure

sorting members of structure array

大憨熊 提交于 2019-11-30 08:38:24
Given a structure array (in C) I am attempting to print out the results in groups of gender and in sub order by numerical order. For example: struct employee{ char gender[13] char name[13]; int id; }; Say I define the structure array like so: struct employee info[2]={{"male","Matt",1234},{"female","Jessica",2345},{"male","Josh",1235}}; How could I go about printing the results like 1234 Matt 1235 Josh 2345 Jessica You'll need to implement a sorting function that compares the structs as you require int compare(const void *s1, const void *s2) { struct employee *e1 = (struct employee *)s1; struct

When should we not use #pragma pack?

爷,独闯天下 提交于 2019-11-30 06:41:12
In C, when we use structures, when would it be inappropriate to use #pragma pack directive..? an addition to the question..... Can someone please explain more on how might the accessing of unaligned data specially with a pointer fail? Firmware developer here. #pragma pack is very familiar territory. I'll explain. In general you should not use #pragma pack . Yes, it will make your structures smaller in memory since it eliminates all padding between struct members. But it can make accessing those members much more expensive since the members may no longer fall along their required alignment. For

uml classdiagram constructor with parameters

♀尐吖头ヾ 提交于 2019-11-30 06:34:00
问题 I am a complete ROOKIE at this so I need some help on it. How would you create uml class diagram and constructors with parameters. for default (no parameters) you do policyholder() for diagram and pseudo-code for parameters would you do the same thing policyholder (policynumber, service class, and customer age) for class diagrams and pseudo-code. It also asked to initialize each attribute to value where an object of this type can be instantiated, If a policy number is not between 1000 and 999

Size of generic structure

∥☆過路亽.° 提交于 2019-11-30 05:06:31
问题 I need to find out a size of a generic structure (I can not do it like sizeof(T) or using Marshal.SizeOf(...) 0> gives me an error) So I wrote: public static class HelperMethods { static HelperMethods() { SizeOfType = createSizeOfFunc(); } public static int SizeOf<T>() { return SizeOfType(typeof(T)); } public static readonly Func<Type, int> SizeOfType = null; private static Func<Type, int> createSizeOfFunc() { var dm = new DynamicMethod("SizeOfType", typeof(int), new Type[] { typeof(Type) });

Display image of graph in TensorFlow?

让人想犯罪 __ 提交于 2019-11-30 04:47:43
I wrote a simple script to calculate the golden ratio from 1,2,5. Is there a way to actually produce a visual through tensorflow (possibly with the aid of matplotlib or networkx ) of the actual graph structure? The doc of tensorflow is pretty similar to a factor graph so I was wondering: How can an image of the graph structure be generated through tensorflow? In this example below, it would be C_1, C_2, C_3 as individual nodes, and then C_1 would have the tf.sqrt operation followed by the operation that brings them together. Maybe the graph structure (nodes,edges) can be imported into networkx

Delphi: Store data in somekind of structure

萝らか妹 提交于 2019-11-30 02:32:21
For a simulation program I'm working in Delphi 2010. The simulation isn't a problem but I need to use large collection of data which gives a problem. The data is available in excel sheets, so there is no need to edit this data in Delphi, but collecting this data from the excel sheets takes around 10min. This isn't a problem as long as you don't need to collect the data every time the program runs. So I made a program which collects all the data makes it visible, not problems here,and then store it. However I can't store it to a "Delphi format" , without losing the structure, so it can be

How can I learn to write well-structured programs in Perl? [closed]

那年仲夏 提交于 2019-11-30 02:06:24
I've started learning Perl but most of my former programming experience has been in languages that emphasize object oriented programming such as C# and Java. All the Perl examples I have found tend to be long single function programs and I find my self writing code the same way. Are there any resources or tutorials for writing maintainable well structured programs? Firstly, regardless of what sort of Perl programming you're doing, you'll probably find Perl::Critic to be invaluable. The command-line tool is by far the most convenient for getting feedback on your code, but you there is also a

When to use a union and when to use a structure

泪湿孤枕 提交于 2019-11-29 21:45:26
问题 I know the differences between union and structure. But from a design and coding perspective what are the various use cases of using a union instead of a structure? One is a space optimization. Are there any more advantages of using them? 回答1: There's really only two major uses. The first is to create a discriminated union. That's probably what you were thinking of by "space optimization," but there's a bit more to it. You need an extra bit of data to know which member of the union is "alive"

C++ - How to write and read a structure that contain an object ? (to write and read binary)

我们两清 提交于 2019-11-29 17:55:49
I'm trying to write a C structure in a file (to write in binary) and read it to recover it. I don't know if it is possible. Here is what I have : head.hh: #include <iostream> typedef struct s_test { char cmd[5]; std::string str; }t_test; main.cpp: #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include "head.hh" int main() { t_test test; int fd = open("test", O_APPEND | O_CREAT | O_TRUNC | O_WRONLY, 0666); test.cmd[0] = 's'; test.cmd[1] = 'm'; test.cmd[2] = 's'; test.cmd[3] = 'g'; test.str = "hello world"; write(fd, &test, sizeof(t_test)); close(fd); fd =

Marshall array of structures

前提是你 提交于 2019-11-29 17:53:17
问题 I've spent a lot of time to look for the solution but still don't find it out. I have 2 classes: [StructLayout(LayoutKind.Sequential)] public class Result { public int Number; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)] public string Name; public int Size; } [StructLayout(LayoutKind.Sequential)] public class CoverObject { public int NumOfResults; [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 4)] public Result[] Results; } My expectation that the