Questions tagged [lab5]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
5 views

lab5 memory leakage - Why is the function not working even using calloc?

Tried many iterations and even changed the allocation to calloc() that i read it frees memory used by NULL or undefined data and still get the same error. in create_family(int_generations) // TODO: ...
0
votes
1answer
16 views

In lab5, why using syntatic sugar like "--generations" doesn´t work (we have to use "generations - 1")?

Could anyone explain the difference between "variable - 1", "--variable" and "variable--"? In lab5 I have noticed that this difference is responsible for breaking the ...
0
votes
1answer
31 views

I'm having a segmentation fault on Inheritance, Lab 5

I've narrowed it down to line 57 x->alleles[i]=x->parents[i]->alleles[0]; I don't understand why it's not working, any help would be appreciated. Here's the full create_family function: // ...
0
votes
1answer
69 views

Inheritance - Lab 5

#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <time.h> // Each person has two parents and two alleles typedef struct person { struct person *parents[2]; ...
0
votes
1answer
9 views

I have a segmentation fault in Lab5, about free_family function

// Free `p` and all ancestors of `p`. void free_family(person *p) { while (p != NULL) { free_family(p->parents[0]); free_family(p->parents[1]); free(p); } ...
0
votes
1answer
38 views

free_family does not work properly | INHERITANCE

I have executed following code for free family function - void free_family(person *p) { // TODO: Handle base case if(p->parents[0] == NULL && p->parents[1] == NULL) { ...
0
votes
0answers
26 views

Lab 5 valgrind error only with specific variable name

I am currently doing lab 5:Inheritance on CS50. I came across a interesting error. when i create a person object with the name person as follows, //Create a new individual with generations person *...
1
vote
1answer
185 views

When does a recursive function actually repeat?

I was just wondering when exactly a recursive function repeats itself. Below is code from inheritance.c from CS50's Lab 5: person *create_family(int generations) { // TODO: Allocate memory for new ...
0
votes
1answer
115 views

Lab5 free_family function

I have created the below function to free memory allocated by the create_family. // Free `p` and all ancestors of `p`. void free_family(person *p) { // TODO: Handle base case if(p == NULL) ...
0
votes
1answer
180 views

Lab 5 Check50 Error Question

When I run Check50 I get an error. I have watched the hint video and my code matches what is shown. I have attached a screenshot of my error as well as the code below. Thank you for the help! person *...
1
vote
2answers
1k views

Segmentation Fault on Inheritance, Lab 5

I tried lab4 but I was having issues so I watched Brian's solution walkthrough. The code compiles and all goes well but when I run the program it shows a segmentation fault. debug50 shows a segfault ...
0
votes
1answer
46 views

stdbool.h in lab5 inheritance

Does anyone know the reason for including (stdloob.h) in lab5 ? what is the importance of this header file in the code ? I already check it without including this file and it was ok.