We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [struct]

A keyword in various programming languages whose syntax is similar to or derived from C (C++, C#, Swift, Go, Rust, etc.). Use a specific programming language tag to tag questions involving use of a `struct` as syntax and semantics can be language dependent. Keyword defines or declares a data type composed of other data types. Each member of a struct has its own area of memory (as opposed to a `union` whose members share a single area of memory).

Filter by
Sorted by
Tagged with
1
vote
2answers
43 views

Read access violation, error code 0xFFFFFFFFFFFFFFFF

I'm sorry this is a repeat question, but no solutions seem to work for my code. This is for an assignment in school on reading from a file and copying the data to an array. An exception is thrown ...
0
votes
0answers
24 views

accessing char* or char array in struct C

ok im having a problem i cant figure out. i have a struct in header file. typedef struct client_t{ char cName[MAX_BRNAME]; char cLname[MAX_BRNAME]; int id; int clientBrNum; int accNum; ...
0
votes
1answer
45 views

How to initialize a doubly linked list with the following structs?

This is my code, I know I did not write much, but I am not knowing how to initialize a doubly linked list with the given structs. The given structs (I can`t change anything in them) /* a node in the ...
0
votes
0answers
21 views

Cython: convert a C struct (with not only simple types) to a Python object [duplicate]

For a project I need to modify a part of sklearn source code and I ran into some issues using cython library. I have a C struct defined as: cdef struct split_info_struct: # Same as the SplitInfo ...
0
votes
1answer
43 views

Create a function that takes a structure (or a pointer to the structure) as parameter and sorts the names in alphabetical order

I create a structure with 3 names,and I want to create a function that takes a structure (or a pointer to the structure) as parameter and sorts the names in alphabetical order. I don't know how to fix ...
-4
votes
2answers
90 views

what is '*' in struct fuction?

struct Node *addToEmpty(struct Node *last, int data) { // This function is only for empty list if (last != NULL) return last; // Creating a node dynamically. struct Node *temp = ...
-2
votes
3answers
77 views

What is the size of a structure pointer in C?

If the size of a structure pointer is 4 or say 8 bytes, how can it properly allocate the required memory for its data members in Dynamic Memory Allocation. This is my code: #include<stdio.h> ...
3
votes
1answer
74 views

What is the efficient way to copy vectors of one data type into a vector of struct of the same data type?

I have a a vector of struct with 3 member variables (vec3)pos (vec3)norm (vec2)texCoord and I have have 3 other independent vectors of (vec3)x (vec3)y (vec2)z respectively, I want to copy/combine the ...
-1
votes
0answers
22 views

Creating a function that will multiply fractions using structs

Write a function void printFraction(Fraction f) which prints out a fraction in the following format; e.g. if the numerator is 2 and the denominator is 5, it will print out 2/5 Write a function ...
-1
votes
1answer
42 views

How do you print out a specific record from a .dat file?

I am working on a project for my computer science class and I am trying to (as a user) be able to read a certain record from a .dat file, print it out. I am able to create the file, enter new records, ...
1
vote
4answers
83 views

How to implement a C# generic class whose methods are generic on structs?

Say we have this pair of structs, part of a widely used interchange format (so we cannot modify the source - and ideally shouldn't want to: we're not trying to alter the data itself): struct Vector2 {...
-1
votes
0answers
40 views

Pointer to struct with non-type template parameter [on hold]

EDIT: solved. The code example below is correct. The problem was caused by the pointer and struct name conflict. Is it possible to initialize a struct with non-type template parameters dynamically? ...
-2
votes
1answer
27 views

How to assign char[] to null inside the struct

I m trying to assign null to char name[] inside the struct; however, it not working #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <...
0
votes
2answers
30 views

Nested template struct constructor implementation

How do I create a nested template struct implementration? For example, if I have: foo.h: template<class T> class foo { template<class U> struct bar { U u; bar(...
-1
votes
0answers
13 views

Defining a struct of m-ary tree - C

I am beginner to C, and this term we study C and C++. Now we have to build some project in C which includes some topics like structs, pointers, files, memory allocations, etc... The main idea in this ...
0
votes
0answers
33 views

Problem while saving data into a linked list in C

I'm developing a program that read some path from an input file passed as arguments and then read recursively or not the path it contains and saves them into a structure. The input file is the ...
0
votes
1answer
22 views

Erro While calculating Euclidean Distance between Two Nodes of a Map

I have a Node represents a point on the Map, and I want to write a function to get the Euclidean Distance between two Nodes, I have written this Code, but It didn't Work, I don't know why ! Can you ...
0
votes
1answer
23 views

Am having difficulties with linked lists

I am trying to learn linked lists and I am just making this program for practice. It contains several linked lists made from two structs. Everything from the struct letterLink works fine (typedef ss) ...
-2
votes
0answers
10 views

Searching for record (row) matching the ID (as a command argument) of a CSV file, deleting that row and save the file in C then print resulting CSV

I'm stuck with a problem involving structs, and apologies if this question seems lazy/ not bothering to put effort by I'm very inexperienced with coding and English isn't my first language so i'm ...
2
votes
1answer
25 views

Matlab: How to sort a struct by one of its columns using another vector

How can I order a struct in a way that one of its columns are equal to a certain vector? Below is an example which shows what I mean. I have the following struct and vector: % What I have: my_struct ...
-3
votes
2answers
70 views

“expected primary expression before '.' token” when working with structs and arrays

I'm currently working on a small c++ project and I use it as practice for a final exam, so this could be a silly error. So... the thing is, I declared an array of structs for using it as a shopping ...
0
votes
1answer
18 views

How to check if a boost fusion sequence is an adapted struct?

Is there a trait or meta function or anything to check at compile time if a sequence is actually an adapted struct, so that I could e.g. get its member names? I saw people doing that by exclusion, ...
0
votes
0answers
57 views

Concurrently manipulate structs

I have a Rust program where I am trying to manipulate two electrical engines at once (simultaneously). I want them to move along X and Y axis at once. It is also important to persist previous position ...
0
votes
4answers
64 views

Segmentation fault when trying to print out a struct

I'm trying to make a code that will allow the user to input any amount of entries he wants, and then print them out (and other functions, still have to get to that). But when I try to launch the code ...
1
vote
1answer
50 views

How to pass typedef'd definitions between source files using encapsulation?

In the link provided- https://embeddedgurus.com/barr-code/2010/11/what-belongs-in-a-c-h-header-file/ Michael Barr states the following: DON’T expose the internal format of any module-specific data ...
0
votes
1answer
49 views

calling model dynamically in go

Consider products like jeans, shirts, shorts and I want to store the orders in respective product tables for eg jeans related order should get stored in jeans tables and so on. Every table would have ...
0
votes
2answers
57 views

Is there any way to make a function smartly in C such that it performs different functions in different values of arguments?

😄 I have to create 2 structs namely rectangle and oval, where the rectangle structure contains its length and breadth and the oval structure contains the lengths of its semi-minor and semi-major ...
-1
votes
1answer
29 views

Where should I place head for a linked list, inside or outside struct?

Is it best to keep the head (double pointer) of a linked list inside or outside the structure for the linked list itself?
-6
votes
0answers
45 views

Trouble with C homework problem involving pointers and structs [on hold]

I'm working on a problem for my C programming class that has me very confused. The requirements are listed below. In summary, the assignment is asking me to write a function that dynamically modifies ...
1
vote
1answer
28 views

Without initialising a vector in a struct, will it automatically be empty or will it have a random memory location's values?

I have some structs with vectors in them. I've assigned other variables in the struct with values, but I haven't referred to the vector at all. When referring to my vector contained within the ...
0
votes
1answer
29 views

Can I cast a tuple struct enum variant into a regular tuple instead of destructuring and recreating the tuple?

I have a tuple struct enum variant that looks like this: enum Message { ChangeColor(u8, u8, u8), // ... } Later, I have a match construct to detect if a variable is of the ChangeColor ...
-1
votes
2answers
53 views

vector<string> in a struct doesn't work properly

I declared a vector<string> and I cannot even compile it. I tried many ways but none of them worked. I'm trying to write out the x.surname.push_back(word)[i] but it's definetly written wrongly ...
-2
votes
1answer
54 views

C++ / Not initializing a value to a const variable in a STRUCT doesn't cause my compiler to yell at me, Why? [on hold]

Basically, i know that i MUST initialize a value to a const variable, but today i experimented to declare a const int in a struct without initializing it, and it compiled. For exemple, this compiles :...
0
votes
1answer
28 views

C stack implementation using structures

my professor doesn't explain much and just gives tasks to complete. I saw similar task here Push Item into Stack with C ,but I wish I could see full code, since I don't understand what top and node ...
0
votes
1answer
43 views

Can I marshal data from a C/C++ struct into a C# struct with properties?

I have a C# struct which is used for interfacing with some native code. Let's say it looks like this and there's an entry point in the dll that can be used to retrieve values for this struct: public ...
0
votes
2answers
49 views

Vector of (Structs having vector)

The following piece of code as stated in Bjarne Stroustroup's C++: Programming and Principles struct Day { vector <double> hour { vector <double> (24,-7777)} }; struct Month { ...
1
vote
1answer
50 views

Bind request method POST

I have a problem with binding my request, because param is lot of, so I used struct contain param . package api import ( "github.com/labstack/echo/v4" "net/http" "trains-api/domain/models"...
0
votes
0answers
16 views

Pyarrow table create column from existing columns

Is there a way to use append_column to create a column based on columns that currently exist in a pyarrow table? I want to create a pa.struct() field using columns that already exist. Looking for ...
-1
votes
2answers
26 views

Getting undefined for a nested struct property

(The previously linked "answer" does not answer this question. stackoverflow.com/questions/24809235/initialize-a-nested-struct. Please do not close this question unless you can provide a clear answer....
0
votes
1answer
34 views

Is there a better way to organize this behaviour as a collection of traits?

I'm putting together an audio dsp and I'm looking for a more "rustacean" way to implement the following: pub struct TransformOptions<SourceType> { transform : Option<Box<dyn ...
2
votes
2answers
41 views

How to split binary data and convert it into numbers in PHP?

I'm reading keyboard events from /dev/input/. Those are input_event structs, respectively five numbers as 24 bytes in little endian format. This is my current solution: $hex = bin2hex(fread($dev, 24)...
-1
votes
0answers
34 views

Send a C data structure with scapy? [on hold]

How can I send a C data structure with scapy? For example, if I need to send the ex structure in this example: struct data { int a; int b; }; struct data ex; ex.a = 4; ex.b = 5;
0
votes
0answers
35 views

simplifying code for an elimination function in a tree

The background info and check-expects for my function are the same as for current my second most recent question, save for the fact that this function should NOT cascade (i.e. it should only delete ...
-6
votes
1answer
69 views

Why do I have undefined identifiers? [on hold]

I am editing this code https://pastebin.com/WR58xL4f where I only use functions, into a code where I put the functions inside of a class. I am having some problems with some undefined identifiers in ...
2
votes
3answers
61 views

Is there any way to keep the return type of a function variable?

I want to define a function, that returns either a struct with multiple values of variant type or a single int * depending on arguments, a user passes over the command line.I know, that I could just ...
0
votes
0answers
37 views

Losing Data when switching to another view controller Xcode SWIFT

Im having trouble figuring out exactly whats going on. Basically, Im opening my first view controller which takes a users info from firebase. i.e. the name and uid. Im sending data by didSet() in my ...
0
votes
0answers
23 views

Why python struct adds padding when a short would be placed to an odd address? (Python 3.7.2)

The code section below fails with Exception has occurred: error unpack requires a buffer of 52 bytes self.masterstructdef = 'HH8sHBBBBHLHHHHBBBBBBBHHLL' strcut.unpack(self.masterstructdef, buffer) ...
0
votes
1answer
42 views

C structs and typedefs

I am not sure why this does not work. I am a bit confused about the typedef's typedef struct cache_line { int valid; int tag; int usage; } cache_line_t; typedef cache_line_t* cache_set_t;...
0
votes
1answer
37 views

Validating POST JSON body matches struct

I'm having trouble validating if JSON body passed to my POST endpoints matches the struct created for the acceptable JSON body. Any help would be appreciated type NewUser struct { UserID string ...
0
votes
1answer
23 views

Why does my direct Equals call pass, but fails when nested? [duplicate]

I am attempting to implement Equals overrides for some structs in my code. I have the following "child" struct public struct ChildStruct { public bool Valid; public int Value1; public ...