Questions tagged as 'struct'

1
answer

Stock and Sales Control

Hello, this program is a stock control, which it asks for in the first% program%, an inventory and sale controller with struct. Cases 3 and 4 are in trouble because I do not know how to get the information from the registered items. Case 2 also...
asked by 03.09.2014 / 06:15
1
answer

Read char array from a binary file

Function that writes and reads the binary file: int FUNCAO_QUE_GRAVA_BIN (char filename[],int partida1,char resultado1) { typedef struct { int partida; char jogvelha[3][3]; char resultad...
asked by 27.11.2018 / 12:20
1
answer

___ erkimt __ dynamic array allocation within a struct ______ qstntxt ___

statement and code:

  

Make a program that stores movies produced by several directors   and:       - Create and read a vector of 5 directors, each containing name (maximum 20 letters), number of films       and movies. The movie member is a vector, which must be created after reading the number of movies. Each       film is composed of name, year and duration.       - Look for a director by name, showing all the movies he has already produced. Repeat the process       until you enter an empty string.

%pre%

My question is: am I allocating the array correctly?

It does not work when I try to put more than 2 movies in the same director! Thank you.

    
______ azszpr336404 ___
  

My question is: am I allocating the array correctly?

Not at all. The allocation was done based on the %code% size, allocating a %code% vector but the %code% type is %code% :

%pre%

In other words, it has allocated a vector of directors and saved it in a double char pointer, so the types and sizes do not play. If your array is an array of %code% to save strings declared as %code% then the correct allocation would be:

%pre%

Note that I omitted cast because it is not required. I should also add that calling the %code% field would be much brighter than it represents, instead of %code% .

But I can not help saying that this does not answer the statement. The statement clearly states that:

  

Each movie consists of name, year and duration

Then %code% should be a structure:

%pre%

And now this would be the structure used within %code% :

%pre%

The allocation would now be:

%pre%

Now it's not enough to adjust the remaining code for this new movie structure.

    
___

statement and code:    Make a program that stores movies produced by several directors   and:       - Create and read a vector of 5 directors, each containing name (maximum 20 letters), number of films       and movies. The movie member is a...
asked by 15.10.2018 / 02:49
1
answer

Error referencing struct with pointers

I'm trying to convert this algorithm down into language c but I having trouble calling the variable and assigning a value to the p.key = 1 of the struct element. Error Code: error: request for member 'key' in something not a structure o...
asked by 04.11.2018 / 00:41
2
answers

How to pass structure data to a text file?

I have this structure: struct televisao { int id_guit; int precodia; int preco; int estado; char nome[20]; }; I wanted to ask the user to insert data from this structure and save it to a .txt file, how do I get it? The p...
asked by 30.05.2018 / 20:18
1
answer

List sorted C ++ struct

I need to do a job with this struct and it contains insert, search and delete by year and impression. Only I'm with doubt in the following code. I need it right after the insert is sorted. struct mundial{ int ano; char sede[10];...
asked by 29.05.2018 / 19:52
2
answers

Problem in compiling string in C

I'm trying to compile this code in 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 matricula; int coef; }TipoAluno...
asked by 02.06.2018 / 18:06
1
answer

Structs in C can have constructors?

I have the following structure within a program: struct STR00034ST{ char C_O010XC14B, C_O020XC14B; short S_0010XI15C; float F_0010XI1D; STR00034ST (char _C_O010XC14B, char _C_O020XC14B, short _S_0010XI15C, float _F_0010...
asked by 19.02.2018 / 10:03
1
answer

Reading txt file in C and interpreting the data

I need to read txt files in C and interpret the data from within the files. The files contain parts in TEXT and others in DECIMAL / WHOLE numbers. What I need is to read the whole file and pass the numbers to a Cartesian coordinate structure. Fo...
asked by 27.04.2017 / 07:32
1
answer

Function for matching points

In an exercise, I need to create a function that returns TRUE if the points are identical. For the points, a structure was implemented as follows: typedef struct //Estrutura definida para os pontos. { double x; //Coordenadas X e Y. dou...
asked by 26.06.2017 / 19:22