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
-
2
votes2
answers167
viewsHow do I pass an array of structure pointers to a function?
#include <stdio.h> #include <stdlib.h> #define NUM_NOTAS 5 #define TAM_NOME 20 struct Aluno{ char nome[TAM_NOME]; int numero; int notas[NUM_NOTAS]; }; void preenche(struct Aluno*…
-
2
votes1
answer77
viewsWhy does this work? pointer = (struct a *)&b;
struct a { int a; int b; }; struct b { int a; int b; }; struct a *ponteiroa; struct b b; b.b = 20; ponteiroa = &b; //Isto não dá certo ponteiroa = (struct a *)&b; Why is this (struct a…
-
2
votes3
answers548
viewsError using scanf("%[ n]") in sequence
#include <stdio.h> typedef struct person{ char name[100]; char address[100]; int age; } Person; int main() { Person pessoa; printf("Digite seu nome:\n"); scanf("%99[^\n]", pessoa.name);…
-
2
votes1
answer516
viewsDifference between using struct and class to create an object
He had already "learned" object orientation in college, right on top of it. Now that I’ve started to revise I realize that no matter how much they say structs do not form objects, I really see no…
-
2
votes1
answer122
viewsHow to copy a structure pointer?
Is it possible to clone a structure pointer? Follow the code: typedef struct{ int numero; }estrutura; int main(int argc, char *argv[]){ estrutura *i = (estrutura *)malloc(sizeof(estrutura));…
-
2
votes1
answer4013
viewsBinary file storage
In the program, I need to implement a structure that represents a student (name, age and enrollment). Using this structure, I have to write a program that reads the data of 5 students and stores it…
-
2
votes1
answer91
viewsLinked List - append and push
I’m trying to learn Linked List and I made the following code: #include <iostream> using namespace std; typedef struct snode { int data; snode *next; } node; void start(node ** head) {…
-
2
votes1
answer499
viewsHow do I resolve struct statement Warning?
I’ll send the code and the warnings that GCC is reporting. I must ignore warnings? The warnings are related as the passage of struct for the job Inserir();: #include <stdio.h> #include…
-
2
votes3
answers77
viewsMicro class system in C
What I would like is to automatically initialize a struct that receives function pointers. For example: struct teste{ int x; int y; int (*soma)(int, int); }; typedef struct teste Teste; int soma(int…
-
2
votes1
answer1586
viewsHow to remove a struct stored in c file?
I don’t think I explained it well in the title I have a schedule code where I can add contact, edit, list and is stored in a calendar file.txt only that I’m having trouble removing a contact that…
-
2
votes1
answer131
viewsC pointers
Well, guys, I’m doing graph theory on C, and I tried to use dynamic allocation to create an array. Also, my code has a function to fill the matrix with 1 in the received indexes. But I have some…
-
2
votes1
answer198
viewsC - How to pass an array in which it contains pointers to struct as a function parameter?
First I created a struct vector. Next I created a pointer vector, in which each element of this vector points to each element of the struct vector. Finally, I need to pass both (the struct vector…
-
2
votes1
answer1942
viewsSort list on in C
My problem involves reading data from a text file, where is provided the CPF, name, email, age, sort using list sort in ascending order through age, if you are equal age sort by Cpf. But I’m having…
-
2
votes1
answer238
viewsHow to pass a dynamically allocated struct to a C function?
The program must dynamically allocate the struct and pass it as parameter. #include <stdio.h> #include <stdlib.h> typedef struct cadastro_de_mercadoria{ int codigo; int estoque; }…
-
2
votes1
answer84
viewsHow to assign character array in a structure?
The program reads 10 films, each film has gender name, and age rating, then lists; I’m having trouble assigning matrix string (I think it’s just that mistake) #include <stdlib.h> #include…
-
2
votes1
answer84
viewsDoubt - Dynamic list
I have the following structure for my dynamic list: typedef struct DataNode { int id; } DataNode; typedef struct Node { DataNode data; struct Node *Next; } Node; typedef struct List { int size; Node…
-
2
votes3
answers80
viewsDo I need to re-allocate a structure in case I clean up just a part of it?
I have a struct who owns nome and horário for appointments. typedef Struct{ char nome[20]; char data[20]; }Dados; I make the statement: Dados *dados_cliente[quantidade]; I make the allocation…
-
2
votes1
answer70
viewsSerialize/Deserializar struct for sending via sockets
I have a struct that I would like to serialize/disallow to send in a connection via sockets using the function send and recover that struct with the function recv, what are the ways I can solve this…
-
2
votes1
answer499
viewsProblem with chained list in C
I am doing a college job where basically the Program should be done in C language using chained lists and have 3 options: Add music (beginning, middle or end of list) with name, band and duration;…
-
1
votes2
answers580
viewsStruct with pointer and allocation
I can’t use the fscanf in a structure, I have already allotted the structures. #include <stdlib.h> #include <stdio.h> #include <string.h> struct Cliente { int numero; char *nome;…
-
1
votes2
answers4640
viewsAverage calculation problem between int and float
I’m having a problem with an average calculation. I have a struct with 3 fields. The ones I’m looking for are average product quantity and unit value. I need to average all the products and their…
-
1
votes1
answer375
viewsHelp: Valuing a char vector of a struct within an if
I’m trying to define the value of a char vector of a struct within an if, but without success... The struct itself: struct ficha { char nome[31], classificacao[31], telefone[21]; float altura, peso,…
-
1
votes2
answers115
viewsSegmentation Fault in Structs C array
I’m trying to make an array of dynamic structs in C, but I don’t understand why it’s returning to me. The code is basically this: I’m just creating a vector of 10 arrays and then trying to…
-
1
votes1
answer562
viewsHow to adjust the format dd/mm/yyyy
I have the following code that takes the instant date from the computer. #include <Windows.h> #include <stdio.h> #include <time.h> void main () { time_t t = time(NULL); struct tm…
-
1
votes1
answer5855
viewsPointer of struct inside a struct
I cannot assign value to a variable of a pointer struct within a struct. My structs: typedef struct notas{ float geral; float especifica; }Notas; typedef struct data{ int dia,mes,ano; }Data; typedef…
-
1
votes3
answers2790
viewsRead a string with line break
I need to compare two strings to see if they are equal. One of them is in a vector of struct and was dealt with the fgets, so it’s a line break. The other one is informed by the keyboard. I wonder…
-
1
votes1
answer161
viewsFunction that returns pointer gives crash when trying to return pointer to main program
I have this function that retrieves a record from a binary file already filled with records - such records are structured as Node - and returns it to the program. Only in the return of "i" for the…
-
1
votes1
answer3534
viewsPass and return vector of type defined by struct as parameter of a function in C
I’m finding errors for the following code: #include<stdlib.h> #include<stdio.h> #include<stdbool.h> #include <locale.h> #define true 1 #define false 0 const int limite = 100;…
-
1
votes1
answer657
viewsSize of struct allocation
When declaring a normal variable of type int for example, the compiler goes there and, depending on the architecture, separates 4 bytes. struct exemplo{ int x; int b; }; int main(){ struct exemplo…
c++ pointer struct memory-management allocationasked 9 years, 9 months ago Alexsander Borgesdamaceno 541 -
1
votes1
answer86
viewsI can’t call a string
I created an algorithm that simulates a stock of a dvd sales. It stores name, price and quantity. It has some functions and it enters them, one that informs the quantity and the price of a specific…
-
1
votes2
answers2642
viewsPhysically delete a struct type record
I need to physically delete a record created within a struct defined in my program, but in every way I tried (Define it as NULL, Create another struct and save all records that were not deleted on…
-
1
votes1
answer254
viewsDynamic allocation and pointers in Lua
I would like to know how I make dynamic allocation and pointer of a structure in Lua, I have the following instruction in C that I need to pass to Lua; typedef struct ilha { char name; struct ilha…
-
1
votes2
answers1405
viewsProblem with Struct in C
In that code: #include <stdio.h> #include <stdlib.h> //Usando o struct(Estruturas) struct cadastro { char nome[50]; int idade; char rua[50]; int numero; }; int main() { printf("Digite…
-
1
votes4
answers316
views"Pure" structs (no pointer) and C error handling
Messing with data structures (filas, pilhas, etc), I reached an impasse in trying to create search functions for these structures. By default, functions that can contain errors return 0 or even -1…
-
1
votes1
answer556
views -
1
votes2
answers147
views -
1
votes2
answers313
viewsHow to access the pointer of a struct within the pointer of another struct?
typedef struct vertice { int num_vertice; int profundidade; struct vertice **vertices_adja; } Vertice; typedef struct grafo { int qtd_vertices; int *Vertice; } Grafo; I want to access the attributes…
-
1
votes2
answers276
views -
1
votes1
answer184
viewsBuild error with struct
While trying to compile I am facing the following error: ..: error: storage size of 'PPFila' isn't known ..: error: storage size of 'AUTFila' isn't known On this code line struct Fila PPFila,…
-
1
votes1
answer112
views -
1
votes1
answer337
viewsError importing structs from a header file
I need to use the following structures without changing their file implementations .h. typedef unsigned long int chave_t; typedef unsigned long int conteudo_t; typedef struct entrada_hash{ chave_t…
-
1
votes1
answer324
viewsProblem with reading Bitmaps in C
I’m having trouble reading files Bitmap. Results not as expected. The size is always the same regardless of which image I open Height and width do not match the size stated in the image viewer The…
-
1
votes1
answer477
viewsHow to increment the index of an unlimited array?
How can I increment an array within a structure? This is my structure: struct list { char name[50]; int products_list[]; } LIST[10]; I wanted to know the current number of elements in the array…
-
1
votes1
answer153
viewsPass C struct to lua script
When I got past my frame Book to the script in Moon, the method writes the value as nil. How I pass the structure Book to my moon code? main. c: #include <lua.h> #include <lualib.h>…
-
1
votes1
answer129
viewsError assigning value to struct property in C++
I’m learning to code and, at the moment, trying to make a little game like the popular Nake. We need to increase several things in the program, such as the limits of the walls, collisions, etc...…
-
1
votes1
answer317
viewsHelp with C nested structs
I was creating in C a list and using a struct, after finishing I tried to see what changed with a struct nestled, created two structs basic, one receiving only one value and another receiving this…
-
1
votes1
answer1897
viewsHow to use pointer and vector in a single struct in C?
I cannot run a program that needs functions to execute a procedure, this function receives a vector of type struct by means of a pointer. There is no build error, but the program hangs while running…
-
1
votes1
answer593
viewsRead from a txt file via fscanf using vector
I have the following while(!feof(f)){ (*ptr).push_back(carro()); fscanf (f, "%d", (*ptr)[add].id); fscanf (f, "%s", (*ptr)[add].marca); add++; } Where *ptr is &vector, a vector of a car struct,…
-
1
votes1
answer440
viewsHow to order a struct within a struct
I am wanting to do ordering of a struct that is referenced within another struct: Detail: can be a sort using Selection Sort typedef struct{ int tipo; char dispositivo[50]; int prioridade; }Perif;…
-
1
votes1
answer113
viewsRelation between structs in C
I have the following scenario: typedef struct Unidade{ int cod; } und; typedef struct Produto{ int cod; char nome[100]; und unidade; } prod; As you can see I have a unit type variable inside the…