Most voted "struct" questions
A struct or structure is a composite data type consisting of one or more variables grouped under a name.
Learn more…405 questions
Sort by count of
-
1
votes1
answer208
viewsProblems with dynamic allocation and struct
I intend to create a struct where there will be a vector of structs... The way I thought of doing it was kind of like this: typedef struct{ char *teste_str; int teste_int; }TESTE_A; typedef struct{…
-
1
votes1
answer594
viewsC Language: Manipulating a vector of structs within functions
Hello, I created a struct: typedef struct { float valor; float peso; } objeto; And within the main() I’ve created a vector of these guys: objeto conjunto[50]; Then I need to swap one 'object' of…
-
1
votes1
answer390
viewsClone a struct without copying the memory address
I need to copy the struct problema1 to the struct problema2 , but to do the way it is in the program below , when I change the struct problema2 also be changing the struct problema1. The way I did…
-
1
votes1
answer407
viewsStruct defined in file. c auxiliary (with definition of functions and structs) is not recognized in main
I’m doing a C project, and I have 3 files: 1 . c containing the definitions of functions and structs. 1 . h containing the prototypes of these functions and structs Ae1 . c containing the main. No .…
-
1
votes1
answer43
viewsError declaring a matrix
I made a matrix[day][time], but I get error when initializing it. I get that mistake and I don’t know how to fix it error: expected ':', ',', ';', '}' or 'attribute' before '=' token The code is…
-
1
votes2
answers497
viewsConflict of types in function
I’m trying to create a list structure using struct. Only when compiling my code, I get an error because even specifying the type Lista, he’s in some kind of trouble. Follow the full code: #include…
-
1
votes1
answer550
viewsHow to pass the field of a struct to a function in a library separately?
Hello, everybody. I have a program that has a structure like this: struct itemDeLista{ char nomeProd[10]; float quant; float vUnit; int item; }; But I need to count the number of letters in the…
-
1
votes1
answer45
viewsStruct presenting problem
I am unable to compile the program shows error in variable declaration struct product, when I try to create an instance in the main. #include <iostream> using namespace std; struct produto;…
-
1
votes2
answers279
viewsProblem with Struct and Function in C
Good evening, I’m having a problem with the code I’m doing. I don’t know if I’m deleting the values correctly (and replacing them with the next one). The error is appearing in the replacement by the…
-
1
votes1
answer62
viewsError in the average calculation of a student record
printf("Nota 1: "); scanf("%.1f", &alu[n].not1); printf("Nota 2: "); scanf("%.1f", &alu[n].not2); alu[n].media = (alu[n].not1+alu[n].not2)/2; // o erro acontece NESSA LINHA invalid operands…
-
1
votes1
answer1567
viewsstrcpy() in struct string
I have a struct Time that has a vector char name[30], the problem starts when I try to copy a value to that string with the function strcpy(), follows the code of stuct: typedef struct Time{ char…
-
1
votes2
answers163
viewsConverting a vector<struct> to C++ into C
I am trying to adapt a C++ function into pure C. I have changed the variable names and structs because it’s beside the point. typedef struct struct1 { int a; int b; int c; string d; } STRUCT1;…
-
1
votes2
answers5472
views -
1
votes2
answers258
viewsUse of struct in C#
I have to record customer information. And I used struct to do this. Is it worth doing this? It is or is not a good practice?…
-
1
votes2
answers100
viewsString compilation problem in C
I’m trying to compile this code into C: #include<stdio.h> #include<string.h> #define tam 100 typedef struct TipoAluno{ char nome[50]="A"; char curso[50]="B"; char cota[50]="C"; int…
-
1
votes1
answer40
viewsHow do I define an element of a Struct in C?
I intend to make a program that uses structs to store data, but that there is already some data inserted in it, I will give a similar example: struct registro { char nome[30], telefone[11]; int…
-
1
votes1
answer434
viewsWhat is the use of struct in c?
I’ve learned how to use the command in a code, but I still don’t understand exactly what it’s for. Could someone explain to me, with examples if possible, their usefulness?
-
1
votes1
answer8780
views -
1
votes1
answer68
viewsStruct with Union is giving invalid usage error
I need to use a union within a struct, but I’m not getting it. The error presented is [Error] invalid use of 'Union Client::document' Struct: struct Cliente{ string nome, email; union documento{…
-
1
votes0
answers134
viewsNested Struct - Difficulty in understanding the concept
I have the following structures: typedef struct DataNode { int id; } DataNode; typedef struct Node { DataNode data; struct Node *Next; } Node; typedef struct List { int size; Node *head; } List; I…
-
1
votes1
answer1518
viewsList (static) operations c++
Good afternoon guys, I’m having a hard time understanding the operations in Statist lists, I know create and display, but how do I remove and search within the list, the sorting algorithms I’ve…
-
1
votes2
answers208
viewsDeclaration of a global array of C structures
I created a structure cliente and the next idea would be to create a array clientes. My idea would be to declare array clientes globally, so that all functions can interact without passing it as an…
-
1
votes1
answer51
viewsWhy can’t I access the data from this struct with the dot, just with the arrow?
I allotted that struct by dynamic allocation and can only access the data idade via arrow and not by point wanted to know why? #include<stdio.h> #include <stdlib.h> struct pessoa { int…
-
1
votes2
answers2484
viewsHow to store contacts from the agenda I created in an array array and list them? C
I’m trying to develop an agenda in C. I would like to know how to store contacts from the agenda I created in an array and list them? I’m also racking my brain when it comes to listing a phone…
-
1
votes1
answer81
viewsStruct receiving the same struct as attribute
Hello, how can I have a "recursive" struct? A struct that takes itself as one of the attributes. typedef struct { int value; NODE[50]; } NODE; In this case, the idea is that each Node has a vector…
-
1
votes1
answer379
viewsWhat are the differences and advantages between "typedef struct" and "struct"?
I saw that the structure statement is not a standard among many programmers, while some use the typedef struct, others use only struct. Which is best to use? Has some difference in performance?…
-
1
votes1
answer264
viewsC - Structures for point, polygonal line and polygon
Good night The exercise asks me to implement three structs: Point (coordinates X and Y), polygonal lines (sequence of 2 to 100 points that are the vertices along the line) and polygon (sequence of 3…
-
1
votes1
answer1259
viewsStruct vector and char pointer
Why is this syntax wrong: #include <stdio.h> typedef struct { char* nome; char* numero; }Agenda; void adiciona(Agenda* reg, int i) { scanf("%s", reg[i]->nome); scanf("%s",…
-
1
votes1
answer51
viewsI don’t understand the following structure
I’m having trouble understanding the following structure: typedef struct TipoItem{ int Chave; } Item; typedef struct TipoCelula *Apontador; //aqui temos um apontador tipo celula. typedef struct…
-
1
votes1
answer462
viewsProblem in ordered insertion code of structs (records) in files
I am doing a work in which I have to insert structs in alphabetical order in archives, in which the structs are political and the archives (which together form a chained list) are the parties. I’m…
-
1
votes1
answer45
viewsSyntax inside a struct that looks like a function
I was analyzing a code in C++ and came across the following structure: struct ligacao { int v_; int w_; int ComEXp; ligacao(int v, int w, int ComEXp1) : v_(v), w_(w), ComEXp(ComEXp1) {} // Minha…
-
1
votes1
answer30
viewsProblems with C/C++ Struct Array
I’m trying to make a program that reads a string and int and stores its values in one struct and then print it on the screen, I’m still learning, forgive me if it’s a very obvious mistake. Code:…
-
1
votes1
answer647
viewsHow to manipulate a vector of structs in an external function? Follow example
I am doubtful on a question. Follow the statement: Implement a library control system with functions to register, query, change and remove books. The attributes of a book are: Name (Book title with…
-
1
votes2
answers396
viewsDoubt about struct and list in c
I’m having trouble when you need to give a value to a person, in case I need to give the value name and age to the person. I tried to create a struct PESSOA and a list containing a person and an id,…
-
1
votes1
answer56
viewsPassing by reference, and saving data from a file in a vector
I’m having trouble saving the read data from a text file and a vector from a structure I created. My goal is to open a text file, take the data that is saved in it, and save in an array of type…
-
1
votes1
answer82
viewsReading only odd records
Initially, I had to create a program to save data from a struct to a file. The struct is as follows:: typedef struct { char nome[30]; int matricula; char conceito; } TipoAluno; I made the program in…
-
1
votes1
answer121
viewsCode matching verification on a vector within a C struct
next, I created a struct struct eventos { int codigo; char data[11]; char atracao[50]; int ingresso; float valoring; }; And then I created a vector that way struct eventos ficha[5]; My goal is to…
-
1
votes1
answer656
viewsassignment to Expression with array type
I’m having an error when associating an array address on a pointer to struct, I’m getting a type error: assignment to Expression with array type The code I’m using is this: struct MaxHeap { int…
-
1
votes1
answer325
viewsAddress type Struct for INT
I have the following Struct: struct nodo{ int elo_a; char nick[26]; char cidade[16]; int idade; int elo_p;}; I have both struct assignments: struct nodo *variavel; struct nodo *offline; Ok, I…
-
1
votes1
answer362
viewsHow to sort array structures based on the rank of the songs?
The rank of the code ta going in ascending order but the others do not change the positions along with the rank, as I do for the positions of the songs and styles go along with the code ? #include…
-
1
votes1
answer100
viewsHow to pass structure to function?
An agency in a small town has a maximum of 10,000 clients. Develop an algorithm that can enter each client’s account number, name and balance. The algorithm must print all accounts, their balances…
-
1
votes2
answers113
viewsError translating structure code from C++ to C#
I’m trying to read a string of a process, I found this structure on the Internet: struct name { wchar_t nome[32]; }; I did it that way: struct name { public char[] nome = new char[32]; } And is…
-
1
votes0
answers57
viewsC code only compiles once and then closes
I have a code that I am writing in C, and then a problem is constantly happening. I don’t know if it has anything to do with memory allocation. I have a function: struct elementodos…
-
1
votes2
answers1571
viewsReading Binary File in C++
Good morning. I’m trying to make a read of structs that I inserted in a binary file, but is giving error at the time of reading. Follow the code of the reading function: void lerRegistros(char*…
-
1
votes2
answers75
viewsHow do I define Operator= for a c++ struct?
I have the structure to follow: struct PATH { vector<ARCO_TEMPO> rota; set<int> rotaAux; float COST; int nArcosVoyage; vector<bool> VisitedNodes; vector<vector<bool>>…
-
1
votes0
answers91
viewsWhat is the Bubble short error in this code?
I tried to solve this problem of URI Online Judge and I came to this code, and it works for test cases smaller than the problem, and I’ve already looked for the bug, only I can’t find it. Code:…
-
1
votes1
answer172
viewsHow to access elements of a vector of a type defined by struct?
In my code, I made the following statement of struct: struct material { int idmaterial; double rho; double precokg; }; I wanted to run this function, which reads data from a file:…
-
1
votes1
answer147
viewsSwitch command does not work and shows no errors
I’m trying to solve the following exercise: Devise an algorithm that assists in controlling a cattle farm that has a total of 2,000 head of cattle. The database consists of a set of structures…
-
1
votes2
answers2198
viewsProgram Ignoring the Scanf
I need to create an algorithm as requested below, but every time I run the program it "skips" steps. For example: I want you to stay like this Product: "Potato" Sector: "Food" Quantity: "15" Price:…
-
1
votes1
answer211
viewsPointer Statement in a struct and calling it in function
I must solve the following problem by creating a function for reading, one for calculation and using pointers. #include <stdio.h> #include <stdlib.h> #include <math.h> struct ponto…