Questions tagged as 'c'

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

Why do not you enter the notes loop?

I am storing student names and notes and trying to display the name, grade, and grade. The problem is that the program is jumping the notes loop and is just picking up the name. #include <stdio.h> #include <stdlib.h> #include <s...
asked by 19.09.2018 / 21:20
1
answer

Factorial function does not return

I need to use function in C but it is not returning the factorial.    Problem: "Given an integer n, compute its factorial n !.   factorial of a number is given by the equation: n! = n(n
asked by 20.09.2018 / 15:04
1
answer

How to improve performance on this code

I made the question The Legend of Flavious Josephus but the timeout expired , what I can change to shorten the time My code #include <stdio.h> void carregaVetor(int *vetor, int numero); void removeNum(int *vetor, int *cont, int *ta...
asked by 25.08.2018 / 13:48
1
answer

What is this Arduino code doing?

I need a description of what it does. if( ! digitalRead(sensor1)) { speed1 = frente; speedv1=0; } else { speed1 = 0; speedv1 = voltar; }     
asked by 27.08.2018 / 21:56
1
answer

Array of strings and pointers

Read the comments in the code #include <stdio.h> int main(void) { char *nomes[2][2]; //Eu não entendo porque se eu tirar esse ponteiro * o codigo dá erro nomes[0][0]="Misael"; nomes[0][1]="Zaes"; nomes[1][0]="Joao"; nomes[...
asked by 11.08.2018 / 20:06
1
answer

How to make the program stop in each printf?

I would like to make the user type printf() at a time, being "Name, RG and Email" but as soon as I type the name, it executes everything else and ends the program, how do I stop it in the next printf() for the user? int main () {...
asked by 22.10.2018 / 00:02
1
answer

Multiply n numbers in c

What reason for my code, regardless of the numbers typed multiply with the number that I placed for the condition of the loop to be false? I just wanted to multiply the values I typed and not to multiply the number to leave the loop. #include...
asked by 30.08.2018 / 23:20
2
answers

Problem in the parameter of a function

#include <stdio.h> #include <stdlib.h> int pos_setinha(int x); void menu(int x); int main() {int x=0; do { menu(pos_setinha(x)); } while(1); } int pos_setinha(int x) { x=0; char C; C=getch(); switch(C) { cas...
asked by 05.07.2018 / 15:14
1
answer

Recursive Heapsort in C

I have a heapsort, and would like to implement it recursively. What do I need to change in my algorithm? void criarHeap(int v[], int inicio, int final){ int aux = v[inicio];//v[pai]//inicio=pai int filho = (inicio * 2)+1;//i=filho whil...
asked by 05.08.2018 / 18:39