Skip to main content

Questions tagged [lab5]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
29 views

Lab 5 - Inheritance check50 error

Attempted CS50 Lab 5 inheritance. My code looks correct and compiles. I also double-checked with Brian's solution and they were identical. Yet when I passed it through check50, I got multiple errors ...
Jarret's user avatar
  • 1
0 votes
1 answer
6 views

p is assigned a memory first but when create family is called again, isnt the last memory lost as now p points at a new chunk of memory?

person *p = malloc(sizeof(person)); // If there are still generations left to create if (generations > 1) { // Create two new parents for current person by recursively calling create_family ...
Omer Matin's user avatar
1 vote
1 answer
86 views

Lab 5 Inheritance Segmentation Fault

I'm getting a segmentation fault on my code for Lab 5. Debug50 says line 57 is to blame, and when I look at the info, it looks like parent0 and parent1 are both empty? (If I'm understanding 0x0 right?)...
scarmonies's user avatar
0 votes
2 answers
279 views

Segmentation Fault on lab5 Inheritance

I'm trying to do lab5 inheritance. The code compiles and prints the correct output but ends with "Segmentation fault (core dumped)" debug50 shows a segfault on line 86: free_family(p->...
Tybirk's user avatar
  • 1
0 votes
1 answer
43 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 ...
João Ricardo's user avatar
0 votes
1 answer
160 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: // ...
Mainlander's user avatar
0 votes
1 answer
2k 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[...
user01's user avatar
  • 7
0 votes
1 answer
23 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); } ...
fried fish's user avatar
0 votes
1 answer
462 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) { ...
MWD's user avatar
  • 86
1 vote
1 answer
307 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 ...
orangecat94's user avatar
0 votes
1 answer
305 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) ...
Multiplify's user avatar
0 votes
1 answer
428 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 *...
sevo's user avatar
  • 3
1 vote
2 answers
2k 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 ...
ehsansth's user avatar
0 votes
1 answer
115 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.
Aya Othman's user avatar