Click here to Skip to main content
15,891,863 members
Everything / Structures

Structures

structures

Great Reads

by honey the codewitch
BinaryReader needs a better way to read strings and types. Here's a quick and dirty fix
by Member 13797506
Introduction to structs (value types) in Java
by Alex the Green Apple
C library defining string type and string manipulation functions
by Sergey Vystoropskiy
C++ low level design

Latest Articles

by honey the codewitch
BinaryReader needs a better way to read strings and types. Here's a quick and dirty fix
by Member 13797506
Introduction to structs (value types) in Java
by Alex the Green Apple
C library defining string type and string manipulation functions
by George Jonsson
Generic C# equivalent of the bit field struct in C

All Articles

Sort by Score

Structures 

23 Apr 2021 by honey the codewitch
BinaryReader needs a better way to read strings and types. Here's a quick and dirty fix
12 May 2014 by Sergey Alexandrovich Kryukov
First of all, you should understand the difference between GC action (finalization and reclaiming managed memory) and finalization. Disposal (System.IDisposable) is a separate mechanism which can be used to clean-up everything. It is often used to dispose unmanaged resource, but it is not the...
21 Mar 2013 by Richard MacCutchan
See here[^] for full details of the C++ language.
27 Jul 2016 by Richard MacCutchan
tree *root = NULL; // Create new root from the class tree of the header fileroot = root.Insert(root, 9); // New node with the number 9 on itThe first statement creates a pointer and sets it to NULL, so it does not point to anything. You then try and call the Insert method on a NULL...
5 Dec 2012 by OriginalGriff
A very, very simple Google search woudl have found you this info a lot quicker than asking here - it's not as if it's a new question.Have a look at this: http://programmers.stackexchange.com/questions/92339/when-do-you-use-a-struct-instead-of-a-class[^] which covers it pretty well.In...
18 Mar 2013 by Joezer BH
See Marshalling C++ array in struct to C# struct[^]Cheers, Edo
23 Mar 2013 by OriginalGriff
No.When you declare a pointer to something, whatever it is, you are declaring a variable whose type is "pointer to object" - not an instance of the object itself. Initially, a pointer will be null - it points to no instance so any attempt to use it without assigning an instance address to it...
23 Mar 2013 by H.Brydon
For the purpose of your question (and ignoring the syntax problems), use of either 'class' or 'struct' generates identical behavior (there are other differences here but not in the scope of your question).When you create 2 objects with:A a1;A* a2 = new A();then a1 is created on...
9 Nov 2014 by Sergey Alexandrovich Kryukov
This is because iVum is private (default); to be accessible, it should be internal or public.Your code and post look as if you tried to write some application before reading a manual on the language and platform. Such approach is counter-productive.—SA
11 May 2015 by User 59241
You have a singly linked list: http://en.wikipedia.org/wiki/Linked_list[^]The steps are:1. Find the node you wish to delete - target2. Find the previous node.3. Point next in previous node to the next that target node points to.4. Delete target...
10 Jun 2015 by User 59241
You only created an array of 2 members passengerinfo[2]Trypassengerinfo[10]AND also limit the number of values input to 10 pairs.
29 Mar 2016 by Jochen Arndt
This is sourced by the alignment of struct members. You can use the pack[^] pragma to ensure that there are no fill bytes in your structure:// Push current setting and pack to one byte boundary #pragma pack(push, 1)typedef struct NetCfgPacket // 81 bytes{char stx;// ...} RP_N;//...
2 Jan 2018 by Rick York
Here is how initialize the structure : struct str { char arr1[4]; // this string is limited to three characters plus null char arr2[4]; int num1[4]; int num2[4]; }; struct str select = { "Sam", "Joe", { 0, 1, 2, 3 },...
19 Aug 2018 by OriginalGriff
Well... look at your code. printf("else it's working!!!!!!!!!!!!!!!!'\n"); while(t->link!=NULL) { t=t->link; (/*
30 Sep 2020 by Sandeep Mewara
Quote: A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only...
24 Mar 2013 by Maxim Kartavenkov
In additionally to previous answers.A a; // object created in stackA * pa = &a; // But it still have a pointer and you can get it next way// Now if you call any method of the those 2 instances you call it on same object.a.Method();pa->Method();// And set property performed also on...
19 Aug 2013 by OriginalGriff
There are two ways: one is to explicitly cast the object you retrieve from the ArrayList back to a Details structure:Dim detail As Details = TryCast(strucStatementInfo.strMaster(i), Details)If detail IsNot Nothing Then With detail ... End WithEnd IfBut the better way is...
23 Oct 2013 by thatraja
Hereafter don't include multiple unrelated questions while posting questions.Quote:Don't Answer as links directly give some information as Answer to my questionsOK, I'll tryQuote:1)What is Razor is it having any relation with java script?Yes, Razor is a View. You could include javascript...
25 Nov 2013 by OriginalGriff
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...A very quick search using your subject as the search term gave 42 million hits: Google[^]The top hit is Wikipedia: http://en.wikipedia.org/wiki/Linked_list[^] which...
13 Sep 2014 by OriginalGriff
You need to go back to your notes and have a good read - then have a good look at your code and think about what you are trying to do.Your search does nothing, or at least, nothing useful - because you don't bother with the result it returns, it doesn't matter what it does return.But...
8 Mar 2015 by KarstenK
In a linked list all item are linked, so if you delete one the linkage gets lost. So if you want to delete one, you need predecessor and the successor to successfully remove one element.before deletion:predecessor -> obsolet -> successor after deletion:predecessor -> successor So...
15 Sep 2015 by OriginalGriff
This isn't a site for criticising your tutor: it's a site for professionals who are willing to help others when they get stuck.We aren't here to do your homework, or critique his questions.So sit down, read what you are supposed to do and give it a try.If you meet a specific problem,...
25 Sep 2015 by Richard MacCutchan
As an imaginary responder I imagine this is your homework, so don't expect other people to do it for you.
16 Oct 2015 by bling
Don't kill yourself trying to become an expert at data marshaling when you don't need to be one.Create a new VB.NET assembly (say "Types") and put all your data structures there.Add a reference to this assembly in both the native and existing VB.NET projects.Enable managed eg....
21 May 2016 by Richard MacCutchan
T is just a placeholder for the real type that will be used wherever class foo appears later in your source code. see Templates (C++)[^]
11 Jul 2016 by CPallini
That's callsed Serialization, see Serialization - Wikipedia, the free encyclopedia[^].Quote:is it practically wrong to write it in text format ?No, it is not wrong. In fact, some serialization mechanisms use text files. It is a bit inefficient, though.Have a look at this page: C -...
30 Jul 2016 by Patrice T
Try to replaceval = nodo->val; // At this point the data is gone, now it shows trashwithnodo->val = val;it should solve the data gone problem.This syntax is really weird.Q1->nodo = Q1->PushQ(Q1->nodo, 5);Otherwise, push is really buggy, a completed analyze and rewrite is in...
19 Sep 2017 by Jochen Arndt
There are three errors in your code. The first two ones: You have a fixed array size of 10 for row and col but are accessing 11 elements (out of bound access) and did not initialise all elements: for (int i=0; i
29 Oct 2017 by Patrice T
Quote: Palindrome using queues It is your right to make things as complicated as you want, but don't complain if nobody want to follow you on this track. To check if a string is a palindrome, I need 2 variables Albert Einstein said: Everything should be made as simple as possible, but no...
29 Oct 2017 by Richard MacCutchan
You have two pointers in the node, next points to the next node in the list, or NULL if there are no more. previous points to the (obviously) previous node in the list, or NULL if it is the first. You manage your list by initialising a pointer with the address of the first node in the list. As...
25 Feb 2018 by phil.o
To generate a random number either 1 or 2, you can use the following code: #include int random_number = (rand() % 2) + 1; Hope this helps.
25 Mar 2018 by KarstenK
Thats sounds poor, because iteration is one main standout feature of the vector container class. If your vector is sorted I would suggest the faster binary search but I think that you may consider this in a later stage of your project.
27 Apr 2018 by Member 13797506
Introduction to structs (value types) in Java
17 Mar 2021 by OriginalGriff
size_t is an unsigned datatype - it has no concept of negative numbers, so when you cast the integer value -1 to size_t what you get is a very large value because negative integers are stored with the top bit set: an eight bit value for -1 would...
4 May 2021 by Richard MacCutchan
This is essentially the same question you already posted at List windows services in a file using C[^]. And I already explained how you need to allocate the memory for the returned data. And again you are trying to extract data from a buffer that...
29 Oct 2021 by deXo-fan
Hello, I've noticed that whenever you write a program in Visual Studio that uses structs (or classes), the assembly code generated doesn't contain a single MASM STRUCTURE, even though it would perfectly fine. Instead, VC++ does something I...
26 Oct 2021 by den2k88
Assembly does not have structs. MASM does but it is its own interpretation of Assembly. Indeed the name itself means Macro ASseMbler and STRUCT is one of these macros, provided to help the developers. This kind of additional keywords is normal...
15 Dec 2021 by OriginalGriff
In C (and thus C++) any non-zero value is true - so the loop you found will continue to loop until i has been reduced to zero. Challenges aren't about "finding a code" and submitting it: they are supposed to be "learning experiences" where you...
9 Sep 2022 by Rick York
You are already doing that in your code. Maybe you should read this : map::find - C++ Reference[^] because that is what you are doing currently and that is how you find values in a map.
13 Sep 2022 by Rick York
I am not sure how this even compiles. The item m_map is declared as a typedef but I see no instance of that type declared. Anyway, the documentation for map::begin has sample code that displays a map's contents : map::begin - C++ Reference[^].
4 Jan 2023 by OriginalGriff
Because it doesn't compile. if (nMAX) { printf("Invalid numbers!"); }``` "`" is not a valid character in C code, so the compiler doesn't like the final line of that code fragment. If code doesn't compile, then no .EXE file is...
22 Aug 2012 by dsandru1
I have a DLL that I have imported using P/Invoke and I am trying to pass a structure of character pointers to. DataIn will be filled with an array of hex bytes, and DataOut will be filled during the AssembleSecurityPacket(). I am having trouble getting the dll to fill the output array, DataOut....
22 Aug 2012 by Kuthuparakkal
few ideas will get you started: char* : string PrefIn ="mypref"; unsafe { IntPtr ptrPrefIn = Marshal.StringToHGlobalAnsi(PrefIn); char* _ptrPrefIn = (char*)ptrPrefIn.ToPointer(); } Structure:object _oStruct ; // some...
22 Aug 2012 by JackDingler
It looks like you've coded this so that you only get two entries of in 'DriveList'You might split those into separate records.Or just remove the for loop and change the log line:Tools.Log( "Drive %s\\ has a status of \"%s\". %.0fGB Free Space, %.0fGB Total Space. %.0f%% Free Space",...
24 Aug 2012 by dsandru1
I figured out how to do this.I changed my struct to look like this: [StructLayout(LayoutKind.Sequential)]public class sSecurityLayer{ public byte Header_no; public byte Code; [MarshalAs(UnmanagedType.LPStr)] public string DataIn; public int DataInLen; ...
2 Mar 2013 by YvesDaoust
See the matrix as a set of nested squares. You can rotate each square independently. To rotate a square by N positions, you can rotate it N times by one position. To rotate by one position, save one element to extra storage, shift the others circularly and put back the saved element.A B C D...
18 Mar 2013 by GustavoUgioni
Hello guys, I need to use a C++ Dll at C#, so I figure that I need to re-write some structs and enums. I have this code at my header file in C++.#pragma mark STRUCTURES typedef void* QCam_Handle; typedef struct _TAG_CAM_SETTINGS_ID_GUID_STRUCT_ { uint32_t...
23 Mar 2013 by hor_313
HiAre two (a) in this codes equal?class A ();A a;OR A* a;And also it about structures
10 Aug 2013 by Zoltán Zörgő
Manas Bhardwaj is totally right!But at least try to search for yourself.Ah... you know google? Well, look what it has given to me for you: http://cybergrouch.blogspot.hu/2012/03/non-recursive-binary-tree-traversal.html[^]. But don't even dream to give that code as your homework, since your...
10 Aug 2013 by Manfred Rudolf Bihy
From how you posted your question one can assume that you have a tree to traverse where the nodes that are not leafes have some kind of operand in them and the leafes are numbers. Hoping you at least know what preorder, inorder and postorder are this is quite easy to work out using a recursive...
19 Aug 2013 by Luiey Ichigo
Hi all,I want to retrieve data from array.'Variable for assigning data Structure StatementInfo Dim strName As String Dim strAccNo As String Dim strOwnAdd1 As String Dim strOwnAdd2 As String Dim strOwnAdd3 As String Dim...
1 Dec 2013 by Mehdi Gholam
You can get better at anything with time and effort. Find something you enjoy first since that will be easier for you.
18 Feb 2014 by Abdullah Jallad
Hello,I Have Basically a Program table and an ADs Table i need to buled a table that is going to be used as the Playlist (it is for a broadcasting)that my program going to run an algorathem and buled the playlist for the programs First and then i will have an ADs free time (or time...
25 Feb 2014 by Stefan_Lang
No.three.c has no knowledge of the definitions you hid in one.c or two.c. How could they know? That is what headers are for. Read up on headers for C/C++.
10 May 2014 by Elighne
I have this small structure that i use only to manage the contents of some comboboxes instead of a database, by reading from an XML file, but each time the index of another combobox is changed, the contents of the whole combobox gets cleared and refilled, obviously with new structure...
13 May 2014 by theskiguy
I have a VB.net app that I use to communicate with a Fanuc CNC controller with a PC front end using the Fanuc Focas Libraries. The Fanuc CNC controller controls the operation of a machine tool that is used to cut metal parts. The Focas libraries has a series of different functions I can call to...
13 May 2014 by Alan N
Why not just replace the variable size structure ODBAXIS with an integer array allocated at run time with a length one element longer than the expected amount of data, i.e. 9 or 33. The dummy and type fields would now be in element(0) and could be extracted out if actually needed. The data...
23 Jun 2014 by Cédric Poottaren
Dear community members.I would like to know how do I encode a file in Visual Basic so that It can't be opened with a word processor such as Notepad or Word. I want to create a custom structure for a file which will act as a database for my Application. It will be encrypted using a special...
23 Jun 2014 by Dave Kreskowiak
First, creating your own encryption scheme is about as insecure as it gets unless you're holding a PhD in math and cryptology.Second, you can't prevent other applications from opening your data file at all.They will still be able to read the file no matter what you do. It's a matter of...
29 Jul 2014 by Member 10978878
I have the following code that is giving me a Huge problem, and cant seem to figure out why.I stored some information to a file and i want to read it out back but it keeps on reading out 9 variables instead of the 14 and i dont know why.Reading out code ( i have left out some of the code...
13 Sep 2014 by Theja_3895
#include using namespace std;class SLLIST;class node{ private: int ele; node *addrs; public: friend class SLLIST;};class SLLIST{ private: node *head; public: SLLIST() { head='\0'; } void insert_beg(); void insert_end(); void...
13 Sep 2014 by George Jonsson
Some places to study linked listsSingly linked lists in C++[^]C++ TUTORIAL - LINKED LIST EXAMPLES[^]
8 Mar 2015 by Cheres_bk
A small investment company stores data into a singly linked list. Each list element consists of:Customer First nameCustomer unique identifierInvestment typeInvestment amountWrite the corresponding structure and Write the function that removes customer with bad investment (those with...
5 May 2015 by lukeer
Hello forum,is it possible to create a tree data structure in pure C?This is not about a binary tree but every node shall have 0-n children.The tree shall never be changed at runtime. Since this is for an embedded (Microchip Pic32) project, RAM is an issue. So I'd like to store the...
5 May 2015 by Richard MacCutchan
You are trying to mix static and dynamic data, so the compiler does not know how much space to reserve. You probably need a different structure for child nodes that do not themselves have children. You cannot declare an array as NULL as you have tried to do in your child nodes.
7 May 2015 by Frankie-C
As Richard said it is not possible to make what you want with incomplete types and variable lenght arrays, but ...If you don't dislike the dark side of the C, there is a workaround:typedef struct _TreeNode{ int id; char* text; struct _TreeNode* children[1]; // List of child...
1 Jun 2015 by Member 11131925
After a lot of attempts I' m yet to figure out how should I use to fill the array of structures in C# and pass it dynamically to C++Dll.I m pretty confused in regards to how to use the marshalling of the structures.I have an array of structures. I have to send this structure to C++ and...
1 Jun 2015 by KarstenK
It is better to allocate the memory where you will have the results and let it fill from the other side.Take a loke at the article and its sample code.
2 Jun 2015 by fioresoft
not a solution, but a bug, you have i > 7 where it should be
3 Jun 2015 by Member 10772496
Hello world,In my VB.net code I call a C++ dll, which should return a ouput structure.I have a problem when the vb.net code read this structure !The c++ structure is :struct output_data{ SAFEARRAY *output1; SAFEARRAY *output2;}In the VB.net side i declare the...
5 Jun 2015 by Richard MacCutchan
You already posted this question at Calling a C++ DLL function from VB.NET having SAFEARRAY structure[^]. If you have further information then please edit the original, as that already contains some suggestions. Please do not repost.
2 Aug 2015 by Patrice T
Your question tells us that you did not even give a try to the program.To understand what is doing such a simple algorithm, there is certainly nothing better than watching it doing its stuff.Solution 1:- Take a sheet of paper, a pen and do it by hand.- Excel will also do the job...
2 Sep 2015 by Sergey Alexandrovich Kryukov
I see absolutely no reason to do anything unsafe.struct MyStruct { internal abs; bca;}//...MyStruct myStruct = new MyStruct();myStruct.abc = 1;//...—SA
15 Sep 2015 by CPallini
Why, in your opinion, those data structures are 'absurd'?You don't need to find similar exercises, just follow the requirements.Use (if you are allowed) the C++ standard library, your task would be easier.
29 Sep 2015 by Max Melnikov
I create a data collection system that has a tree-like structure built on the similarity to the pattern of the factory, and I have the difficulty in working with this structure, more stingrays lot of code to find the element opredelnie. public interface ITag : IRegister{ string...
14 Oct 2015 by Member 10772496
Hi,I have a problem to pass a structure contained a structure pointer from VB.net to a C++ dll.When i try the following code, this exception is raised :'System.Runtime.InteropServices.COMExceptionIn VB.net side i do :Private Declare Function Cpp_NOR Lib "XLSTATLINK.dll"...
1 Nov 2015 by DotNetSteve
It looks as as though the top and bottom have identical code except for the node type (one being TCP, the other RTU) could you use an interface or base class to code against and eliminate half your code?Example:INode = interfaceTCPNode : INodeRTUNode : INodeINode _node = Either...
2 Jan 2016 by Arthur V. Ratz
Probably this one, I don't actually understand the condition of the problem being described:do{ char name_for_check[10] = "\0"; cin >> name_for_check; if (strcmp("quit", name_for_check)
29 Mar 2016 by Member 12330615
In VC++, I have coded the structure variable in the program:typedef struct NetCfgPacket // 81 bytes{char stx;char cmd;char mac[6];char wantype;char ip[4];char gateway[4];char netmask[4];char dns[4];char devicename[32];char ...
27 Jun 2016 by Patrice T
I agree with you for answer A, but for answer B.Hint: think to what append to stack and queue structures as you add and remove data.
12 Jul 2016 by wedtorque
i am working on a database flat file project using c language .i have created a structure with few members . i am using fwrite() to write them in binary file and fread() to fetch the data .My two major question 1st can we write structure in text file ? i have seen no good example .is it...
11 Jul 2016 by Patrice T
Quote:1st can we write structure in text file ?Yes you can.Quote:i have seen no good example .This your design choice. You decide how the structure translate to file and how you get it back to structure.XML files are used for this all the time. Structures are translates to XML and...
12 Jul 2016 by bling
1st can we write structure in text file ? i have seen no good example .is it practically wrong to write it in text format ?If, by structure, you mean binary data (eg. not ASCII), no you should not use text mode. Open the file as binary if you want to operate on bytes without the C runtime...
27 Jul 2016 by Bit87
Hello, I need some help with this, I'm trying to call a function from my header file to my main, this function return a structure.The problem here is that I don't get how to call a function that returns a structure from it, I have tried some things but nothing has worked. Output...
30 Jul 2016 by Bit87
Hello, I'm trying to make a dynamic queue using linked list to create the nodes of it, but I have some problems with the method of insertion, at one point the data that I pass to the function looses and it returns trash.The main problem is in Nodo* PushQ(Nodo *nodo, int val)The...
30 Jul 2016 by barneyman
i think you mean nodo->val=nodoi assume if(nodo = NULL) is a typo? Must be, otherwise you wouldn't enter that clause in the debugger
14 Sep 2016 by OriginalGriff
Carefully.We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.Try it yourself, you...
14 Sep 2016 by Patrice T
We do not do your HomeWork.HomeWork is not set to test your skills at begging other people to do your work, it is set to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them. Any failure of you will help your teacher spot...
14 Sep 2016 by Karthik_Mahalingam
try thispublic void SomeFunction() { List lst = new List (); lst.AddRange(new int[]{1,2,3,4,-1,-2,-3,-4}); var data = manipulate_data(lst); } public List manipulate_data (List lstInput) { int positiveCount =0; ...
15 Sep 2016 by Arul Prasath Kolandasamy
Can anyone help me to write a code for "template operator overloading without class for complex number addition and multiplication"the main theme is i should not use "class" and i can use structure and i should use "template" to add and multiply for two complex number, i tried to search in...
15 Sep 2016 by CPallini
Why do you need templates for such a task?Could you please show us your 'not working code'?Here an example of global (without class) operator overloading: How to overload opAssign operator globally in C++ - Stack Overflow[^].[update]I give you an example#include using...
22 Dec 2016 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.This stuff is fundamental, and you...
18 Feb 2017 by vivvicks
I have one array which store random numbers. If i replace 1 of this number with zero is it possible that can get replaced values without storing it anywhere?e.g 25-45-67-86-32-65and now 25-45-67-0-32-65want to retrieve 86 with using array properties.What I have tried:i have...
18 Feb 2017 by Peter Leow
How can you remember something if you choose not to remember it? The changed value has to be stored somewhere somehow before it can be recovered, even Windows has that recycle bin. For your question, you could have made a copy of the original array, then the original value of a changed element...
18 Feb 2017 by Patrice T
Quote:Finding value inside array without using historyThe concept of history in array do not exist.If you want this feature, I fear you will have to create it.
3 Apr 2017 by OriginalGriff
For starters, that won't compile at all on many systems: you are lacking some of the forward declarations. You should also include a reference to string.h Then try changing your assignment: ptr = &data; To ptr = data; As a "whole program", this should work: #include ...
3 Apr 2017 by Patrice T
You need to learn C properly, this book is the reference for C. You can also find tutorials. Using the debugger may also help you to understand what is wrong in your program. Here is links to references books on C by the authors of the language. The C Programming Language - Wikipedia, the free...
2 May 2017 by Nawaz Sk
so i just started structure and was interested to implement it to create a adjacency matrix to use in graph related algo implementation so i create a pointer to pointer variable in the graph to use it as the base address for the 2d matrix but when tried to assign memory to the array is showing...
2 May 2017 by KarstenK
Your problem starts earlier by allocating G. G is your pointer array so you need the count of arrays. It is a pointer to an array of pointers. This tutorial brings some insight. Your G is that array of ptr. struct graph *G=(struct graph **)malloc(sizeof(struct *graph) * count); G[i]=(struct...