Student question: how do i remove the segfault | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list User *curr = *user_ptr_del; // If 1 element in the list if (curr->next == NULL) { if (strcmp(curr->name, name) == 0) { *user_ptr_del = NULL; free(curr); } else { return 1; } } while (strcmp(curr->next->name, name) != 0

Question: how do i remove the segfault


Goal: /* * From the list pointed to by *user_ptr_del, delete the user * with the given name. * Return: * - 0 on success. * - 1 if a user with this name does not exist. */ | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list User *curr = *user_ptr_del; // If 1 element in the list if (curr->next == NULL) { if (strcmp(curr->name, name) == 0) { *user_ptr_del = NULL; free(curr); return 0; } else { return 1; } } while (strcmp(curr->next->name,


Goal: /* * From the list pointed to by *user_ptr_del, delete the user * with the given name. * * Return: * - 0 on success. * - 1 if a user with this name does not exist. */ | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list User *curr = *user_ptr_del; User *temp = *user_ptr_del; // If 1 element in the list if (curr->next == NULL) { if (strcmp(curr->name, name) == 0) { temp = *user_ptr_del; } else { return 1; } } while (strcmp(curr->next->


Goal: remove the deleted user from the friendlist | Code context (simplify for kids): void remove_friend(const char *name, User *ptr_friend_user, int index) { User *friend = ptr_friend_user; for (int i = index; i < MAX_FRIENDS - 1; i++) { friend->friends[i] = friend->friends[i + 1]; } } void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; for (int i = 0;


Goal: remove the deleted user from the friendlist | Code context (simplify for kids): void remove_friend(const char *name, User *ptr_friend_user, int index) { User *friend = ptr_friend_user; for (int i = index; i < MAX_FRIENDS - 1; i++) { friend->friends[i] = friend->friends[i + 1]; } } void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr !=


Goal: remove the deleted user from the friendlist | Code context (simplify for kids): void remove_friend(const char *name, User *ptr_friend_user, int index) { User *friend = ptr_friend_user; for (int i = index; i < MAX_FRIENDS - 1; i++) { friend->friends[i] = friend->friends[i + 1]; } friend->friends[MAX_FRIENDS - 1] = NULL; } void remove_friends(const char *name, User **ptr_users) {


Student question: what can i do to fix this so that a user is removed from the friendslist of all users | Code context (simplify for kids): void remove_friend(const char *name, User *ptr_friend_user, int index) { User *friend = ptr_friend_user; for (int i = index; i < MAX_FRIENDS - 1; i++) { friend->friends[i] = friend->friends[i + 1]; } friend->friends[MAX_FRIENDS - 1] = NULL; } void remove_friends(const char *name, User **ptr_users) {

Question: what can i do to fix this so that a user is removed from the friendslist of all users


Goal: delete the user in every friendlist | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { for (int i = 0; i < MAX_FRIENDS; i++) { if (strcmp(curr->friends[i]->name, name) == 0) { for (int j = i; i < MAX_FRIENDS - 1; j ++) { curr->friends[j] = curr->friends[j + 1]; } curr->friends[MAX


Student question: does this remove the friend from the friendlist of every user? and if not how can i fix it | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { for (int i = 0; i < MAX_FRIENDS; i++) { if (strcmp(curr->friends[i]->name, name) == 0) { for (int j = i; i < MAX_FRIENDS - 1; j ++) { curr->friends[j] = curr->friends[j + 1]; } curr->friends[MAX

Question: does this remove the friend from the friendlist of every user? and if not how can i fix it


Student question: will this remove the deleted user from all user's friendlists? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { for (int i = 0; i < MAX_FRIENDS; i++) { if (strcmp(curr->friends[i]->name, name) == 0) { for (int j = i; i < MAX_FRIENDS - 1; j ++) { curr->friends[j] = curr->friends[j + 1]; } curr->friends[MAX

Question: will this remove the deleted user from all user's friendlists?


Student question: will this code remove the user from every friendlist? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } for

Question: will this code remove the user from every friendlist?


Goal: * Make two users friends with each other. This is symmetric - a pointer to * each user must be stored in the 'friends' array of the other. * * New friends must be added in the first empty spot in the 'friends' array. * * Return: * - 0 on success. * - 1 if the two users are already friends. * - 2 if the users are not already friends, but at least one already has * MAX_FRIENDS friends. * - 3 if the  | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Check for User Non-existence // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed


Student question: does this properly shit all the friends after user in the list by one? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } for

Question: does this properly shit all the friends after user in the list by one?


Student question: does this code properly remove a friend from friendlists of all the users by shifting the list to the left by one after in the list after the user we want to remove? if not how can i fix it | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } for

Question: does this code properly remove a friend from friendlists of all the users by shifting the list to the left by one after in the list after the user we want to remove? if not how can i fix it


Student question: do lines 4-14 properly assign variable u_count to the position of the user by the name name in the friends list, and f_count to the number of friends in the friendslist? do lines 16-19 then properly remove the user from the friendlist of the users? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } for

Question: do lines 4-14 properly assign variable u_count to the position of the user by the name name in the friends list, and f_count to the number of friends in the friendslist? do lines 16-19 then properly remove the user from the friendlist of the users?


Student question: how do i properly assign u_count to the index of the removed user in the friendslist? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } for

Question: how do i properly assign u_count to the index of the removed user in the friendslist?


Student question: do lines 4-14 properly assign variable u_count to the position of the user by the name name in the friends list, and f_count to the number of friends in the friendslist? if not, what can i change? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } for

Question: do lines 4-14 properly assign variable u_count to the position of the user by the name name in the friends list, and f_count to the number of friends in the friendslist? if not, what can i change?


Student question: do lines 16-19 then properly remove the user from the friendlist of the users? if not what can i change | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } for

Question: do lines 16-19 then properly remove the user from the friendlist of the users? if not what can i change


Student question: do i need to delete the memory of the removed user in friendslist? and if so how? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { printf("bye"); User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_c

Question: do i need to delete the memory of the removed user in friendslist? and if so how?


Student question: Does this code properly remove friends from the friendlist? what do i need to change or add? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { printf("bye"); User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_c

Question: Does this code properly remove friends from the friendlist? what do i need to change or add?


Student question: how can i fix this so i remove the user from the friendlists? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { printf("bye"); User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_c

Question: how can i fix this so i remove the user from the friendlists?


Student question: how do i delete the user from the friendslist if there is only one friend in the friendslist? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { printf("bye"); User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_c

Question: how do i delete the user from the friendslist if there is only one friend in the friendslist?


Goal: remove the user from all the friendlists of the list of users | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } if


Student question: will this properly remove the user from a 1 element long friendlist of a user? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } if

Question: will this properly remove the user from a 1 element long friendlist of a user?


Student question: is this code correct? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } if

Question: is this code correct?


Student question: what do i need to do to fix this | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } if

Question: what do i need to do to fix this


Student question: will this code correctly remove a user from all friendlists? if not, how can i fix it | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } if

Question: will this code correctly remove a user from all friendlists? if not, how can i fix it


Student question: is this correct | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } if

Question: is this correct


Student question: will this code properly remove the user from a friendlist of length 1? if not, why? | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } if

Question: will this code properly remove the user from a friendlist of length 1? if not, why?


Student question: how do i remove a user from a friendlist of lenght 1 | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } if

Question: how do i remove a user from a friendlist of lenght 1


Student question: will this code properly remove the user from a friendlist of length 1? if not, what can i do to fix it | Code context (simplify for kids): void remove_friends(const char *name, User **ptr_users) { User *curr = *ptr_users; while (curr != NULL) { int f_count = 0; int u_count = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (curr->friends[i] != NULL) { f_count++; if (strcmp(curr->friends[i]->name, name) == 0) { u_count = f_count; } } } if

Question: will this code properly remove the user from a friendlist of length 1? if not, what can i do to fix it


Student question: how do i initialize time_t properly so i can get the current time

Question: how do i initialize time_t properly so i can get the current time


Student question: will this properly set curr_time to the current time without junk bites? how can i fix it | Code context (simplify for kids): time_t curr_time = sizeof(time_t); time(&curr_time); new_post->date = &curr_time;

Question: will this properly set curr_time to the current time without junk bites? how can i fix it


Student question: why do i keep getting the wrong date with this | Code context (simplify for kids): time_t curr_time; time(&curr_time); new_post->date = &curr_time;

Question: why do i keep getting the wrong date with this


Student question: what do i need to change to get the right time | Code context (simplify for kids): time_t curr_time; time(&curr_time); new_post->date = &curr_time;

Question: what do i need to change to get the right time


Student question: how can i allocate space for a time_t date

Question: how can i allocate space for a time_t date


Student question: what do i need to change so the current time is stored in new_post->date, a time_t variable? | Code context (simplify for kids): time_t *curr_time = malloc(sizeof(time_t)); time(curr_time) ; new_post->date = curr_time; free(curr_time);

Question: what do i need to change so the current time is stored in new_post->date, a time_t variable?


Student question: do i need to dereference curr_time when iassign it to new_post->date? how do i do that | Code context (simplify for kids): time_t *curr_time = malloc(sizeof(time_t)); time(curr_time) ; new_post->date = curr_time; free(curr_time);

Question: do i need to dereference curr_time when iassign it to new_post->date? how do i do that


Student question: on which line do i reference curr_time | Code context (simplify for kids): time_t *curr_time = malloc(sizeof(time_t)); time(curr_time) ; new_post->date = curr_time; free(curr_time);

Question: on which line do i reference curr_time


Student question: on which line do i need to reference curr_time so this program gives me the correct time | Code context (simplify for kids): time_t *curr_time = malloc(sizeof(time_t)); time(curr_time) ; new_post->date = curr_time; free(curr_time);

Question: on which line do i need to reference curr_time so this program gives me the correct time


Student question: can i have more free calls than free calls in a function if i called malloc without calling free in another function?

Question: can i have more free calls than free calls in a function if i called malloc without calling free in another function?


Student question: does this code properly free all memory from the linked list | Code context (simplify for kids): Post *curr_post = temp->first_post; while (curr_post != NULL) { free(curr_post->date); free(curr_post); curr_post = NULL; curr_post = curr_post->next; }

Question: does this code properly free all memory from the linked list


Student question: how can i make the code free all memory from the linked list | Code context (simplify for kids): Post *curr_post = temp->first_post; while (curr_post != NULL) { free(curr_post->date); free(curr_post); curr_post = NULL; curr_post = curr_post->next; }

Question: how can i make the code free all memory from the linked list


Student question: do i need to free next | Code context (simplify for kids): Post *curr_post = temp->first_post; while (curr_post != NULL) { free(curr_post->date); free(curr_post); curr_post = NULL; curr_post = curr_post->next; }

Question: do i need to free next


Student question: is this code correct | Code context (simplify for kids): Post *curr_post = temp->first_post; while (curr_post != NULL) { free(curr_post->date); free(curr_post); curr_post = NULL; curr_post = curr_post->next; }

Question: is this code correct


Student question: is this code correct | Code context (simplify for kids): Post *curr_post = temp->first_post; while (curr_post != NULL) { free(curr_post->date); free(curr_post); curr_post = curr_post->next; }

Question: is this code correct


Student question: is memory properly freed here | Code context (simplify for kids): Post *curr_post = temp->first_post; while (curr_post != NULL) { free(curr_post->date); free(curr_post); curr_post = curr_post->next; }

Question: is memory properly freed here


Student question: am i traversing the list properly and deleting the memory properly | Code context (simplify for kids): Post *curr_post = temp->first_post; while (curr_post != NULL) { free(curr_post->date); free(curr_post); curr_post = curr_post->next; }

Question: am i traversing the list properly and deleting the memory properly


Student question: do we always need the same number of malloc calls as free calls? what if there were multiple return statements in if statements and multiple free cals within if statements?

Question: do we always need the same number of malloc calls as free calls? what if there were multiple return statements in if statements and multiple free cals within if statements?


Student question: will this code cause memory leaks? if so, where? | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: will this code cause memory leaks? if so, where?


Student question: how can i fix the memory leak | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: how can i fix the memory leak


Student question: am i missing any free(temp) statements? | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: am i missing any free(temp) statements?


Student question: if i have a struct and i allocated memory for the struct, will i have to free the memory for that struct only, or every attribute of the struct as well?

Question: if i have a struct and i allocated memory for the struct, will i have to free the memory for that struct only, or every attribute of the struct as well?


Student question: where are the memory leaks | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: where are the memory leaks


Student question: are there memory leaks in lines 56-62 | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: are there memory leaks in lines 56-62


Student question: what do i need to change to ensure the memory of the posts are being freed | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: what do i need to change to ensure the memory of the posts are being freed


Student question: do lines 56-62 properly free the post memory? if not, how can i fix this? what line do i need to add or change and where? | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: do lines 56-62 properly free the post memory? if not, how can i fix this? what line do i need to add or change and where?


Student question: on which lines do the memory leaks occur? | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: on which lines do the memory leaks occur?


Student question: how would i free all the memory by traversing through a linked list? what code should i write?

Question: how would i free all the memory by traversing through a linked list? what code should i write?


Student question: why is there a memory leak after freeing the posts? | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: why is there a memory leak after freeing the posts?


Student question: how can i fix the memory leak when freeing the posts | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: how can i fix the memory leak when freeing the posts


Student question: the memory leak is caused by the if (curr_post != NULL) statement. how can i fix this | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list // Create a variable to traverse the list User *curr = *user_ptr_del; // Create a variable to hold the deleted user User *temp = *user_ptr_del; // Check for empty users list if (*user_ptr_del == NULL) { return 1; } rem

Question: the memory leak is caused by the if (curr_post != NULL) statement. how can i fix this


Goal: delete all posts and free the memory | Code context (simplify for kids): Post *curr_post = temp->first_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { free(curr_post->date); free(curr_post); curr_post = curr_post->next; } free(curr_post->date); free(curr_post); }


Goal: delete all posts and free the memory | Code context (simplify for kids): // Free post memory Post *curr_post = temp->first_post; Post *temp_post = temp->first_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { temp_post = curr_post free(curr_post->date); free(curr_post); curr


Goal: delete all posts and free the memory | Code context (simplify for kids): // Free post memory Post *curr_post = temp->first_post; Post *temp_post = temp->first_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { temp_post = curr_post; free(curr_post->date); free(curr_post); cur


Goal: delete all posts and free the memory | Code context (simplify for kids): // Free post memory Post *curr_post = temp->first_post; Post *temp_post = curr_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { temp_post = curr_post; free(curr_post->date); free(curr_post); curr_post


Student question: how can i fix the segmentation fault | Code context (simplify for kids): // Free post memory Post *curr_post = temp->first_post; Post *temp_post = curr_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { temp_post = curr_post; free(curr_post->date); free(curr_post); curr_post

Question: how can i fix the segmentation fault


Student question: will this give me a segfault? if so, how can i fix it | Code context (simplify for kids): // Free post memory Post *curr_post = temp->first_post; Post *temp_post = curr_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { temp_post = curr_post; free(temp->date); free(temp); curr_post = curr_pos

Question: will this give me a segfault? if so, how can i fix it


Student question: how do i fix the segfault | Code context (simplify for kids): // Free post memory Post *curr_post = temp->first_post; Post *temp_post = curr_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { temp_post = curr_post; free(temp_post->date); free(temp_post); curr_post

Question: how do i fix the segfault


Student question: what causes the segfault | Code context (simplify for kids): // Free post memory Post *curr_post = temp->first_post; Post *temp_post = curr_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { temp_post = curr_post; curr_post = curr_post->next; free(temp_post->date)

Question: what causes the segfault


Student question: how do i free the last post | Code context (simplify for kids): // Free post memory Post *curr_post = temp->first_post; Post *temp_post = curr_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { temp_post = curr_post; curr_post = curr_post->next; free(temp_post->date)

Question: how do i free the last post


Student question: is this code correct | Code context (simplify for kids): Post *curr_post = temp->first_post; Post *temp_post = curr_post; if (curr_post->next == NULL) { free(curr_post->date); free(curr_post); } else if (curr_post->next !=NULL) { while (curr_post->next != NULL) { temp_post = curr_post; curr_post = curr_post->next; free(temp_post->date); free(temp_post); i

Question: is this code correct


Student question: will this code properly remove the last post? | Code context (simplify for kids): Post *curr_post = temp->first_post; while (curr_post != NULL) { Post *temp_post = curr_post; curr_post = curr_post->next; free(temp_post->date); free(temp_post); }

Question: will this code properly remove the last post?


Student question: will this properly check for a full friendlist | Code context (simplify for kids): // Check for full friends list if (friend1->friends[MAX_FRIENDS - 1] != NULL || friend2->friends[MAX_FRIENDS - 1] != NULL) { return 2; }

Question: will this properly check for a full friendlist


Student question: will this properly check if at least one of the users have a full friendslist | Code context (simplify for kids): // Check for full friends list if (friend1->friends[MAX_FRIENDS - 1] != NULL || friend2->friends[MAX_FRIENDS - 1] != NULL) { return 2; }

Question: will this properly check if at least one of the users have a full friendslist


Student question: will this code work as intended: Make two users friends with each other. This is symmetric - a pointer to * each user must be stored in the 'friends' array of the other. * * New friends must be added in the first empty spot in the 'friends' array. * * Return: * - 0 on success. * - 1 if the two users are already friends. * - 2 if the users are not already friends, but at least one already has * MAX | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: will this code work as intended: Make two users friends with each other. This is symmetric - a pointer to * each user must be stored in the 'friends' array of the other. * * New friends must be added in the first empty spot in the 'friends' array. * * Return: * - 0 on success. * - 1 if the two users are already friends. * - 2 if the users are not already friends, but at least one already has * MAX


Goal: Make two users friends with each other. This is symmetric - a pointer to * each user must be stored in the 'friends' array of the other. * * New friends must be added in the first empty spot in the 'friends' array. * * Return: * - 0 on success. * - 1 if the two users are already friends. * - 2 if the users are not already friends, but at least one already has * MAX_FRIENDS friends. * - 3 if the sa | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed


Student question: why does the first element of friendlist get added to the end of the list when i add the MAX_FRIEND th friend to a friendlist | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: why does the first element of friendlist get added to the end of the list when i add the MAX_FRIEND th friend to a friendlist


Student question: how can i check if the friendlist is already full | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: how can i check if the friendlist is already full


Student question: should i check if the MAX_FRIEND th number or the MAX_FRIEND - 1 th number of the friendlist is null | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: should i check if the MAX_FRIEND th number or the MAX_FRIEND - 1 th number of the friendlist is null


Student question: an extra element is added everytime i added the MAX_FRIENDS th friend. do you know why | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: an extra element is added everytime i added the MAX_FRIENDS th friend. do you know why


Student question: why will The while loop always run at least once, even if f1_added and f2_added are both 1? | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: why will The while loop always run at least once, even if f1_added and f2_added are both 1?


Student question: what do i need to change so that an extra element isnt added everytime i added the MAX_FRIENDS th friend | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: what do i need to change so that an extra element isnt added everytime i added the MAX_FRIENDS th friend


Student question: what do i need to change so that an extra element isnt added everytime i added the MAX_FRIENDS th friend? is this code correct? | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: what do i need to change so that an extra element isnt added everytime i added the MAX_FRIENDS th friend? is this code correct?


Student question: does my code properly check for if the friendlist is full, or if the friend already exists | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: does my code properly check for if the friendlist is full, or if the friend already exists


Student question: is it possible for a friend to be added to the same list twice in my code | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: is it possible for a friend to be added to the same list twice in my code


Student question: is this code correct? if not what do i need to to do to fix it | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: is this code correct? if not what do i need to to do to fix it


Student question: when i run the program, when i add the MAX_FRIEND th name, the first element is added as the MAX_FRIEND th + 1 element. is this function causing that kind of error? | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: when i run the program, when i add the MAX_FRIEND th name, the first element is added as the MAX_FRIEND th + 1 element. is this function causing that kind of error?


Student question: when i run the program, when i add the MAX_FRIEND th name, the first element is added as the MAX_FRIEND th + 1 element. why might the find_user function cause this? | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: when i run the program, when i add the MAX_FRIEND th name, the first element is added as the MAX_FRIEND th + 1 element. why might the find_user function cause this?


Student question: is this code correct? | Code context (simplify for kids): // Keep looping so long as a new friend is not added to both users while ((f1_added == 0 || f2_added == 0) && count < MAX_FRIENDS) { if (friend1->friends[count] == NULL && f1_added == 0) { friend1->friends[count] = friend2; f1_added = 1; // Track that friend2 was added to friend1's friendlist } if (

Question: is this code correct?


Student question: could this code be the reason why the first element of the list is added to the end of the list when the MAX_FRIEND th element is added to a list? | Code context (simplify for kids): // Keep looping so long as a new friend is not added to both users while ((f1_added == 0 || f2_added == 0) && count < MAX_FRIENDS) { if (friend1->friends[count] == NULL && f1_added == 0) { friend1->friends[count] = friend2; f1_added = 1; // Track that friend2 was added to friend1's friendlist } if (

Question: could this code be the reason why the first element of the list is added to the end of the list when the MAX_FRIEND th element is added to a list?


Student question: could this code be the reason why the first element of the list is added to the end of the list when the MAX_FRIEND th element is added to a list? what do i need to add to fix it | Code context (simplify for kids): // Keep looping so long as a new friend is not added to both users while ((f1_added == 0 || f2_added == 0) && count < MAX_FRIENDS) { if (friend1->friends[count] == NULL && f1_added == 0) { friend1->friends[count] = friend2; f1_added = 1; // Track that friend2 was added to friend1's friendlist } if (

Question: could this code be the reason why the first element of the list is added to the end of the list when the MAX_FRIEND th element is added to a list? what do i need to add to fix it


Student question: i dont understand why when i add the MAX_FRIENDS th friend, the first element is added to the end of the list (so it appears twice) | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: i dont understand why when i add the MAX_FRIENDS th friend, the first element is added to the end of the list (so it appears twice)


Student question: will this code always work as inteneded? Make two users friends with each other. This is symmetric - a pointer to * each user must be stored in the 'friends' array of the other. * * New friends must be added in the first empty spot in the 'friends' array. * * Return: * - 0 on success. * - 1 if the two users are already friends. * - 2 if the users are not already friends, but at least one already h | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: will this code always work as inteneded? Make two users friends with each other. This is symmetric - a pointer to * each user must be stored in the 'friends' array of the other. * * New friends must be added in the first empty spot in the 'friends' array. * * Return: * - 0 on success. * - 1 if the two users are already friends. * - 2 if the users are not already friends, but at least one already h


Student question: will this code always work as inteneded? Make two users friends with each other. This is symmetric - a pointer to * each user must be stored in the 'friends' array of the other. * * New friends must be added in the first empty spot in the 'friends' array. * * Return: * - 0 on success. * - 1 if the two users are already friends. * - 2 if the users are not already friends, but at least one already h | Code context (simplify for kids): /* * Helper function that determines if users are already friends */ int check_if_not_friends(User *user1, User *user2) { for (int i = 0; i < MAX_FRIENDS; i++) { if (user1->friends[i] == user2) { return 1; // If user already exists } } return 0; // If user does not exist in friendlist } int make_fri

Question: will this code always work as inteneded? Make two users friends with each other. This is symmetric - a pointer to * each user must be stored in the 'friends' array of the other. * * New friends must be added in the first empty spot in the 'friends' array. * * Return: * - 0 on success. * - 1 if the two users are already friends. * - 2 if the users are not already friends, but at least one already h


Student question: what is a better more correct way to do this? | Code context (simplify for kids): // Create variables to track if the friends were added to each other's // friend lists int f1_added = 0; int f2_added = 0; // Create a counter to track list index int count = 0; // Keep looping so long as a new friend is not added to both users while ((f1_added == 0 || f2_added == 0) && count < MAX_

Question: what is a better more correct way to do this?


Student question: is this code correct | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: is this code correct


Student question: is this correct | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: is this correct


Student question: I have a program that allows you to create users and make them friends with each other. There is a maximum number of friends allowed for each user. when i make two users friends and one of the friend's friendlist is now full, for some reason, in addition to the added friend being added to the friendlist, the first friend that was added to their friendlist is duplicated and added to the very end of

Question: I have a program that allows you to create users and make them friends with each other. There is a maximum number of friends allowed for each user. when i make two users friends and one of the friend's friendlist is now full, for some reason, in addition to the added friend being added to the friendlist, the first friend that was added to their friendlist is duplicated and added to the very end of


Student question: I have a program that allows you to create users and make them friends with each other. There is a maximum number of friends allowed for each user. when i make two users friends and one of the friend's friendlist is now full, for some reason, in addition to the added friend being added to the friendlist, the first friend that was added to their friendlist is duplicated and added to the very end of | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: I have a program that allows you to create users and make them friends with each other. There is a maximum number of friends allowed for each user. when i make two users friends and one of the friend's friendlist is now full, for some reason, in addition to the added friend being added to the friendlist, the first friend that was added to their friendlist is duplicated and added to the very end of


Student question: why is this the case?: If friend1 is added to friend2's friendlist and friend2 is added to friend1's friendlist, then friend1 is added to friend1's friendlist. | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: why is this the case?: If friend1 is added to friend2's friendlist and friend2 is added to friend1's friendlist, then friend1 is added to friend1's friendlist.


Student question: in which cases will this code be wrong? | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: in which cases will this code be wrong?


Student question: when the MAX_FRIEND th element is added, the first element of the friendlist is added too. why are two friends being added when the last element of friendlist is being set? | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: when the MAX_FRIEND th element is added, the first element of the friendlist is added too. why are two friends being added when the last element of friendlist is being set?


Student question: is it possible that this function could add 2 elements to the array of friends instead of 1? when does this happen? how can i prevent this | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: is it possible that this function could add 2 elements to the array of friends instead of 1? when does this happen? how can i prevent this


Student question: why is it that friend1->friends[i]->name is null when the code runs | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { // Create users friend1 and friend2 User *friend1 = find_user(name1, head); User *friend2 = find_user(name2, head); // Check for user non-existence if (friend1 == NULL || friend2 == NULL) { return 4; } // Check for same user passed

Question: why is it that friend1->friends[i]->name is null when the code runs


Student question: will this correctly remove the data in post? should i set it to null as well? | Code context (simplify for kids): void free_posts(Post *post_ptr) { Post *curr = post_ptr; // Create a variable to traverse the linked list while (curr != NULL) { Post *temp_post = curr; // Create a temporary variable to hold a post curr = curr->next; if (temp_post != NULL) { // If the post is not null, free the post and its content

Question: will this correctly remove the data in post? should i set it to null as well?


Student question: will this correctly remove the user and their posts | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list User *curr = *user_ptr_del; // Variable to traverse the list User *temp = curr; // Variable to hold the deleted user // Check for empty users list if (*user_ptr_del == NULL) { return 1; } // Remove the user from all fr

Question: will this correctly remove the user and their posts


Student question: why is it that when i add a post to the user, delete the user and add back the user with the same name,their posts are still there | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list User *curr = *user_ptr_del; // Variable to traverse the list User *temp = curr; // Variable to hold the deleted user // Check for empty users list if (*user_ptr_del == NULL) { return 1; } // Remove the user from all fr

Question: why is it that when i add a post to the user, delete the user and add back the user with the same name,their posts are still there


Student question: do i need to call free_posts anywhere else to correctly remove the posts from the deleted user? | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // Delete user from list User *curr = *user_ptr_del; // Variable to traverse the list User *temp = curr; // Variable to hold the deleted user // Check for empty users list if (*user_ptr_del == NULL) { return 1; } // Remove the user from all fr

Question: do i need to call free_posts anywhere else to correctly remove the posts from the deleted user?


Question: how does strncpy work


Student question: do i need to free memset

Question: do i need to free memset


Student question: how do i initialize user_ptr_add

Question: how do i initialize user_ptr_add


Code context (simplify for kids): #include <stdio.h> #define SIZE 4 #define OVERFLOW 5 int main() { int index = 0; int i; int before[SIZE] = {10, 10, 10, 10}; int a[SIZE] = {0, 0, 0, 0}; int after[SIZE] = {10, 10, 10, 10}; printf("Address of the variables:\n"); for (index = 0; index < SIZE; index++) { printf("%lx -> &after[%d]\n", (


Student question: what is this code doing | Code context (simplify for kids): #include <stdio.h> #define SIZE 4 #define OVERFLOW 5 int main() { int index = 0; int i; int before[SIZE] = {10, 10, 10, 10}; int a[SIZE] = {0, 0, 0, 0}; int after[SIZE] = {10, 10, 10, 10}; printf("Address of the variables:\n"); for (index = 0; index < SIZE; index++) { printf("%lx -> &after[%d]\n", (

Question: what is this code doing


Task: Now start gdb again but before you start, run script gdb_example.txt to record your interaction. (You'll submit this interaction.) This time make sure you watch the array after. It is pretty slow to step through every line of your code, so use list to find the line number of the for loop where we start to assign values to the array. Set a breakpoint on that line number and also set a breakpoint somewhere before that line. Start your program using run and it should run up to the first breakpoint.


Student question: how do you read from an open file passed into as a parameter

Question: how do you read from an open file passed into as a parameter


Student question: when do we dereference variables?

Question: when do we dereference variables?


Student question: in this code, why do we put a * in front of pt on line 5? | Code context (simplify for kids): int num = 40; int *pt; pt = # int *anotherpt = # *pt = 30; printf("%d\n", *anotherpt); return 0;

Question: in this code, why do we put a * in front of pt on line 5?


Student question: what if we did pt = 30? does that work and why? | Code context (simplify for kids): int num = 40; int *pt; pt = # int *anotherpt = # *pt = 30; printf("%d\n", *anotherpt); return 0;

Question: what if we did pt = 30? does that work and why?


Question: when do we use &?


Student question: what would be the value of x[0] | Code context (simplify for kids): char *result[2]; x = result[0]; // some hidden code result[0] = "read only"; y = x[0];

Question: what would be the value of x[0]


Student question: why dont we pass in &arr to function change | Code context (simplify for kids): nt arr[3] = {1, 2, 3}; double result = change(arr, 3); // Comment the above, and uncomment the below, to see // change only work on the 2nd and 3rd integers // double result = change(arr + 1, 2); printf("The array is now: "); for(int i = 0; i < 3; i++) { printf("%d ", arr[i]); } printf("\nAnd the av

Question: why dont we pass in &arr to function change


Student question: whats wrong with this code | Code context (simplify for kids): int *mkarray(int a, int b, int c) { int arr[3]; arr[0] = a; arr[1] = b; arr[2] = c; int *p = arr; return p; } // Code for other_function() omitted. int main() { int *ptr = mkarray(10, 20, 30); other_function(); printf("%d %d %d\n", ptr[0], ptr[1], ptr[2]); }

Question: whats wrong with this code


Student question: when should we be allocating heap space

Question: when should we be allocating heap space


Student question: why doesnt this need malloc | Code context (simplify for kids): double change(int *a, int size) { double sum = 0.0; for(int i = 0; i < size; i++) { a[i] += 10; sum += a[i]; } return sum / size; // assume size > 0 } int main() { int arr[3] = {1, 2, 3}; double result = change(arr, 3); // Comment the above, and uncomment the below, to see // change only work on the

Question: why doesnt this need malloc


Student question: So is it true that we only need to allocate space on the heap when variables with data that we want to persist throughout the program are created in the helper functions?

Question: So is it true that we only need to allocate space on the heap when variables with data that we want to persist throughout the program are created in the helper functions?


Student question: if car.color had pointed to &color_ptr instead, would it change to Blue? | Code context (simplify for kids): struct Car car; char *color_ptr = "Green"; car.color = color_ptr; car.mileage = 1000; color_ptr = "Blue"; struct Car *car_ptr = &car;

Question: if car.color had pointed to &color_ptr instead, would it change to Blue?


Student question: is there a way to change car.color to blue | Code context (simplify for kids): struct Car car; char *color_ptr = "Green"; car.color = color_ptr; car.mileage = 1000; color_ptr = "Blue"; struct Car *car_ptr = &car;

Question: is there a way to change car.color to blue


Goal: modify the program so that the new children do not create additional processes. Only the original parent calls fork. Keep the printf call for all processes. The resulting diagram will look something like the following when parentcreates 3 is run. In this case, the parent process creates 3 child processes. Note that the child process ids will not necessarily be in sequence. | Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol (argv[1], NULL, 10); int is_parent = 0; for (int i = 0; i < iterations; i++) { if (is_parent == 0) { int n = fork(); if (n < 0) { perror("fork"); exit(1); } if (n


Goal: Create a copy of forkloop.c called childcreates.c. In the new file, modify the program so that each process creates exactly one a new process. Keep the printf call for all processes. | Code context (simplify for kids): if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); for (int i = 0; i < iterations; i++) { if (getppid() == getpid()) { int n = fork(); if (n < 0) { perror("fork"); exit(1); } } printf("ppid = %d, pid = %d, i = %d\n", getppid(),


Student question: how can i read a file line by line if i dont know the line length, only the max line length?

Question: how can i read a file line by line if i dont know the line length, only the max line length?


Goal: each process creates exactly one new process | Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int child_count = 0; for (int i = 0; i < iterations; i++) { if (child_count == i) { int n = fork(); if (n < 0) { perror("fork"); exit(1); } els


Task: Your task is to complete checkpasswd.c, which reads a user id and password from stdin, creates a new process to run the validate program, sends it the user id and password, and prints a message to stdout reporting whether the validation is successful.


Question: how do you call wait


Student question: how do i perform write on a newline

Question: how do i perform write on a newline


Student question: how can i get rid of the error | Code context (simplify for kids): write(fd[1], '\n', sizeof(char)); // Write the newline

Question: how can i get rid of the error


Student question: how can i get rid of the error | Code context (simplify for kids): execl("./validate", "validate", user_id, password);

Question: how can i get rid of the error


Student question: why doesn't it properly check if the input is too long | Code context (simplify for kids): if (write(fd[1], password, MAXLINE) == -1) { // Write the password perror("write to pipe"); } if ((close(fd[1])) == -1) { // Close the write perror("close"); } wait(&status); // wait if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { // If it is equal to 0 printf(SUCCESS); } else { printf(INVALID)

Question: why doesn't it properly check if the input is too long


Student question: Your task is to complete checkpasswd.c, which reads a user id and password from stdin, creates a new process to run the validate program, sends it the user id and password, and prints a message to stdout reporting whether the validation is successful. | Code context (simplify for kids): if (write(fd[1], password, MAXLINE) == -1) { // Write the password perror("write to pipe"); } if ((close(fd[1])) == -1) { // Close the write perror("close"); } wait(&status); // wait if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { // If it is equal to 0 printf(SUCCESS); } else { printf(INVALID)

Question: Your task is to complete checkpasswd.c, which reads a user id and password from stdin, creates a new process to run the validate program, sends it the user id and password, and prints a message to stdout reporting whether the validation is successful.


Student question: would this code snippet correctly check for the status | Code context (simplify for kids): wait(&status); // wait if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { // If it is equal to 0 printf(SUCCESS); } else { printf(INVALID); }

Question: would this code snippet correctly check for the status


Student question: is this right | Code context (simplify for kids): if ((r = fork()) > 0) { // If parent process if ((close(fd[0])) == -1) { // Close the read perror("close"); } if (write(fd[1], user_id, MAXLINE) == -1) { // Write the user id perror("write to pipe"); } if (write(fd[1], password, MAXLINE) == -1) { // Write the password perror("write to pipe"); } if (

Question: is this right


Student question: why is user_id properly written to the pipe but password is not | Code context (simplify for kids): if ((r = fork()) > 0) { // If parent process if ((close(fd[0])) == -1) { // Close the read perror("close"); } if (write(fd[1], user_id, MAXLINE) == -1) { // Write the user id perror("write to pipe"); } if (write(fd[1], password, MAXLINE) == -1) { // Write the password perror("write to pipe"); } if (

Question: why is user_id properly written to the pipe but password is not


Student question: would this code properly read 2 things that were written to it | Code context (simplify for kids): } else if (r == 0) { // If child process if ((dup2(fd[0], fileno(stdin))) == -1) { // So it can read from pipe perror("dup2"); exit(1); } if ((close(fd[1])) == -1) { perror("close"); } if ((close(fd[0])) == -1) { perror("close"); } execl("./validate", "validate", NULL); // Validate } else { perror("

Question: would this code properly read 2 things that were written to it


Student question: how can i remove newline characters after calling fgets

Question: how can i remove newline characters after calling fgets


Student question: what can i use to make a copy of a string

Question: what can i use to make a copy of a string


Student question: what does this code do | Code context (simplify for kids): if (line[0] == '\0') { continue; }

Question: what does this code do


Task: A rule is evaluated using the following steps: Update each of the dependencies. In other words, recursively evaluate each dependency rule. Compare the last modified time for each of the dependencies to the target. If the target does not exist, or at least one of the dependencies refers to a file with a last modified time more recent than the target, execute the rule's actions.


Task: Update each of the dependencies. In other words, recursively evaluate each dependency rule. Compare the last modified time for each of the dependencies to the target. If the target does not exist, or at least one of the dependencies refers to a file with a last modified time more recent than the target, execute the rule's actions.


Student question: how do you use stat with examples

Question: how do you use stat with examples


Student question: if im writing a make system, can i: -code a while loop to iterate through the dependencies and recursively call the program on them -after the while loop is finished, check if target exists. if not, execute the rule's' actions -if it does exist, create a struct using stat to hold the modification time of the target rule. loop through its dependencies and check for their modification times. if the

Question: if im writing a make system, can i: -code a while loop to iterate through the dependencies and recursively call the program on them -after the while loop is finished, check if target exists. if not, execute the rule's' actions -if it does exist, create a struct using stat to hold the modification time of the target rule. loop through its dependencies and check for their modification times. if the


Student question: how do you know if If the child terminates with a non-zero exit status

Question: how do you know if If the child terminates with a non-zero exit status


Student question: how do you know if If the child terminates with a non-zero exit status after using execvp

Question: how do you know if If the child terminates with a non-zero exit status after using execvp


Student question: how do you print out multiple strings in an array into one line

Question: how do you print out multiple strings in an array into one line


Student question: how do i concatenate many strings together

Question: how do i concatenate many strings together


Student question: how to initiliaze a string array

Question: how to initiliaze a string array


Student question: can you explain this to me: When pmake is run with the -p option, a child should be created to update each dependency. The parent will create one child process for each dependency and after it has created all of them, the parent will wait for all children to terminate successfully before determining whether it needs to execute the actions.

Question: can you explain this to me: When pmake is run with the -p option, a child should be created to update each dependency. The parent will create one child process for each dependency and after it has created all of them, the parent will wait for all children to terminate successfully before determining whether it needs to execute the actions.


Student question: how do i check if a file/target exists

Question: how do i check if a file/target exists


Task: When pmake is run with the -p option, a child should be created to update each dependency. The parent will create one child process for each dependency and after it has created all of them, the parent will wait for all children to terminate successfully before determining whether it needs to execute the actions.


Student question: can i do this to parallelize a makefile: 1. iterate through the dependencies, and at each dependency, fork the process. If its a child process, recursively call the program, then exit. if it is a parent, then wait. if so, what steps come next?

Question: can i do this to parallelize a makefile: 1. iterate through the dependencies, and at each dependency, fork the process. If its a child process, recursively call the program, then exit. if it is a parent, then wait. if so, what steps come next?


Student question: What does the program print to stderr if the user presses Ctrl+C at the moment when the program is at position B? | Code context (simplify for kids): int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); // POSITION A struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); // POSITION B x += 2; // POSITION C fprintf

Question: What does the program print to stderr if the user presses Ctrl+C at the moment when the program is at position B?


Student question: if im writing a program that executes makefiles, when executing multiple actions, do i need to loop through the actions and then fork once per action?

Question: if im writing a program that executes makefiles, when executing multiple actions, do i need to loop through the actions and then fork once per action?


Student question: run make in parallel | Code context (simplify for kids): Dependency *curr_dep = rule->dependencies; int num_dep = 0; while (curr_dep != NULL) { num_dep++; curr_dep = curr_dep->next_dep; } int child_pid_list[num_dep]; // Create a list to store the pid's of child processes int child_count = 0; // Create a variable to hold the number of children curr_dep = r

Question: run make in parallel


Student question: how do i put a function prototype in another file

Question: how do i put a function prototype in another file


Student question: how do i put a function prototype in another file without a header file

Question: how do i put a function prototype in another file without a header file


Student question: how do i put a function prototype in another file without a header file and without extern

Question: how do i put a function prototype in another file without a header file and without extern


Student question: how do i put a function prototype in another file without a header file and without extern

Question: how do i put a function prototype in another file without a header file and without extern


Student question: does this parallelize make? Note that i later have a for loop that calls waitpid on the list of child_pids | Code context (simplify for kids): if (rule == NULL) { // Base case for recursion return; } // Iterate through dependencies to get the number of dependencies if (rule->dependencies != NULL) { // Check if dependencies exist Dependency *curr_dep = rule->dependencies; int num_dep = 0; while (curr_dep != NULL) { num_dep++; curr_dep = cur

Question: does this parallelize make? Note that i later have a for loop that calls waitpid on the list of child_pids


Student question: is this parallelizeing make? | Code context (simplify for kids): if (rule == NULL) { // Base case for recursion return; } // Iterate through dependencies to get the number of dependencies if (rule->dependencies != NULL) { // Check if dependencies exist Dependency *curr_dep = rule->dependencies; int num_dep = 0; while (curr_dep != NULL) { num_dep++; curr_dep = cur

Question: is this parallelizeing make?


Student question: how do you use sigaction to handle sigprofs

Question: how do you use sigaction to handle sigprofs


Student question: what does updating inbuf mean

Question: what does updating inbuf mean


Student question: what do i need to do here: / You want to move the stuff after the full line to the beginning // of the buffer. A loop can do it, or you can use memmove. // memmove(destination, source, number_of_bytes)

Question: what do i need to do here: / You want to move the stuff after the full line to the beginning // of the buffer. A loop can do it, or you can use memmove. // memmove(destination, source, number_of_bytes)


Student question: is this right so far? | Code context (simplify for kids): while ((nbytes = read(fd, after, room)) > 0) { // Step 1: update inbuf (how many bytes were just added?) inbuf = nbytes; int where; // Step 2: the loop condition below calls find_network_newline // to determine if a full line has been read from the client. // Your next task should be to implement fi

Question: is this right so far?


Student question: did i correctly update inbuf to the correct value | Code context (simplify for kids): char buf[BUFSIZE] = {'\0'}; int inbuf = 0; // How many bytes currently in buffer? int room = sizeof(buf); // How many bytes remaining in buffer? char *after = buf; // Pointer to position after the data in buf int nbytes; while ((nbytes = read(fd, after, room)) > 0) { // Step 1: update inbuf (how man

Question: did i correctly update inbuf to the correct value


Student question: is the correct message being printed | Code context (simplify for kids): while ((where = find_network_newline(buf, inbuf)) > 0) { // where is now the index into buf immediately after // the first network newline // Step 3: Okay, we have a full line. // Output the full line, not including the "\r\n", // using print statement below. // Be sure to put a '\0' in the correct

Question: is the correct message being printed


Student question: is the stuff after the full line moved to the beginning of the buffer and is after and room being correctly updated | Code context (simplify for kids): // Note that we could have also used write to avoid having to // put the '\0' in the buffer. Try using write later! // Step 4: update inbuf and remove the full line from the buffer // There might be stuff after the line, so don't just do inbuf = 0. // You want to move the stuff after the full line t

Question: is the stuff after the full line moved to the beginning of the buffer and is after and room being correctly updated


Student question: how do i do this: Change the code to broadcast to all connected clients

Question: how do i do this: Change the code to broadcast to all connected clients


Student question: client: connect: Connection refused how to fix

Question: client: connect: Connection refused how to fix


Student question: what steps can i take to fix the error client: connect: Connection refused

Question: what steps can i take to fix the error client: connect: Connection refused


Student question: how to change the error: initialization discards ‘const’ qualifier from pointer target type error | Code context (simplify for kids): char *list_users(const User *curr) { // Get the length of the returned string int num_char = 0; User *curr_user = curr;

Question: how to change the error: initialization discards ‘const’ qualifier from pointer target type error


Student question: help me fix this error | Code context (simplify for kids): friends.c : 251 : 9 : error : format not a string literal and no format arguments[-Werror = format - security] 251 | num_bytes_written += snprintf(user_buf + num_bytes_written, num_char - num_bytes_written, print_post(curr)); // Append the post contents

Question: help me fix this error


Student question: How do you use EWOULDBLOCK or EAGAIN to make sure read does not block

Question: How do you use EWOULDBLOCK or EAGAIN to make sure read does not block


Student question: do i need to deal with the remaining data in buffer if I'm reading one line doing partial reads

Question: do i need to deal with the remaining data in buffer if I'm reading one line doing partial reads


Student question: am i passing in the correct user name into process_args | Code context (simplify for kids): while (curr_client != NULL) { if (curr_client->client_soc > -1 && FD_ISSET(curr_client->client_soc, &all_fds)) { char *input = read_input(curr_client->client_soc); if (input == NULL) { // If connection closed printf("Client %d disconnected\n", client_count); } else if (read_from(client_count, users,

Question: am i passing in the correct user name into process_args


Student question: how will the server know which user is using it | Code context (simplify for kids): while (curr_client != NULL) { if (curr_client->client_soc > -1 && FD_ISSET(curr_client->client_soc, &all_fds)) { char *input = read_input(curr_client->client_soc); if (input == NULL) { // If connection closed printf("Client %d disconnected\n", client_count); } else if (read_from(client_count, users,

Question: how will the server know which user is using it


Task: a function called read_input that handles partial reads and returns 1 full line (newline terminated) of input


Question: what is a pointer


Goal: I want to assign the second value of the array to 1. | Code context (simplify for kids): void fib(int **arr, int n){ *arr = malloc(sizeof(int)*(n)); for (int x = 0; x < n; x++){ if (x == 0){ *arr[x] = 0; } if (x == 1){ *arr[x] = 1; } }


Goal: I'm getting a cygwin_exception::open_stackdumpfile error | Code context (simplify for kids): void fib(int **arr, int n){ *arr = malloc(sizeof(int)*(n)); for (int x = 0; x < n; x++){ if (x == 0){ *arr[x] = 0; } if (x == 1){ *arr[x] = 1; } }


Code context (simplify for kids): void fib(int **arr, int n){ *arr = malloc(sizeof(int)*(n)); for (int x = 0; x < n; x++){ if (x == 0){ *arr[x] = 0; } else if (x == 1){ *arr[x] = 1; } else { *arr[x] = *arr[x-1] + *arr[x-2]; printf("%d\n", *arr[x]); } } }


Student question: Am I casting a constant to head? | Code context (simplify for kids): User *find_user(const char *name, const User *head) { while (head != NULL){ if (strncmp(name, head->name, MAX_NAME) == 0){ return (const User*)head; } head = head->next; } return NULL; }

Question: Am I casting a constant to head?


Code context (simplify for kids): int sum_card(int **score_card, int size) { // TODO: write the body of sum_card according to its description. int sum = 0; for (i=0; i<=size; i++) { sum += **score_card[i]; } return sum; }


Code context (simplify for kids): int sum_card(int **score_card, int size) { // TODO: write the body of sum_card according to its description. int sum = 0; for (i=0; i<=size; i++) { sum += *score_card[i]; } return sum; }


Code context (simplify for kids): int sum_card(int **score_card, int size) { // TODO: write the body of sum_card according to its description. int sum = 0; for (i=0; i<=size; i++) { sum += *score_card[i]; } return sum; } /* * NOTE: don't change the main function! * The command line arguments are a sequence of integers that will be *


Code context (simplify for kids): int sum_card(int **score_card, int size) { // TODO: write the body of sum_card according to its description. int sum = 0; for (int i=0; i<=size; i++) { sum += *score_card[i]; } return sum; } /* * NOTE: don't change the main function! * The command line arguments are a sequence of integers that will


Code context (simplify for kids): int main(int argc, char **argv) { int size = argc - 1; int *score_card[size]; for (int i = 0; i < size; i++) { // NOTE: We haven't covered malloc yet, so don't worry about this line. score_card[i] = malloc(sizeof(int)); *(score_card[i]) = strtol(argv[i + 1], NULL, 10); } printf("Sum: %d\n", sum_card


Code context (simplify for kids): int sum_card(int **score_card, int size) { // TODO: write the body of sum_card according to its description. int sum = 0; for (int i=0; i<=size; i++) { sum += score_card[i]; } return sum; }


Student question: Is this a valid way to truncate a string | Code context (simplify for kids): strncpy(s, s, n);

Question: Is this a valid way to truncate a string


Code context (simplify for kids): void list_users(const User *curr) { while (curr != NULL) { printf(curr->name); curr = curr->next; } }


Goal: Print the usernames of all users in the list starting at curr. Names should be printed to standard output, one per line. Is there anything to be fixed? | Code context (simplify for kids): void list_users(const User *curr) { while (curr != NULL) { printf(curr->name); curr = curr->next; } }


Goal: Change the filename for the profile pic of the given user. Return: - 0 on success. - 1 if the file does not exist or cannot be opened. - 2 if the filename is too long. | Code context (simplify for kids): int update_pic(User *user, const char *filename) { /* Check if filename is too long. */ if (strlen(filename) > sizeof(user->profile_pic) - 1) { return 2; } elif (fopen(filename, "r") == NULL) { return 1; } else { user->profile_pic = filename; return 0; } }


Code context (simplify for kids): int update_pic(User *user, const char *filename) { /* Check if filename is too long. */ if (strlen(filename) > sizeof(user->profile_pic) - 1) { return 2; } else if (fopen(filename, "r") == NULL) { return 1; } else { strncpy(user->profile_pic, filename, sizeof(user->profile_pic)); return 0; } }


Student question: If the file does not exist, will fopen() also return NULL? | Code context (simplify for kids): int update_pic(User *user, const char *filename) { /* Check if filename is too long. */ if (strlen(filename) > sizeof(user->profile_pic) - 1) { return 2; } else if (fopen(filename, "r") == NULL) { return 1; } else { strncpy(user->profile_pic, filename, sizeof(user->profile_pic)); return 0; } }

Question: If the file does not exist, will fopen() also return NULL?


Student question: if I have an array of pointers, how can I determine its size?

Question: if I have an array of pointers, how can I determine its size?


Goal: I keep getting a seg fault in line 22 where I want to take this_user's friend list, loop through each friend, and find this_user's index in the friend's friend list. | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; int delete_user(const char *name, User **user_ptr_del) { User *this_user = find_user(name, *us


Student question: I keep getting a seg fault in line 22. I want to take this_user's friend list, loop through each friend, and find this_user's index in the friend's friend list. | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; int delete_user(const char *name, User **user_ptr_del) { User *this_user = find_user(name, *us

Question: I keep getting a seg fault in line 22. I want to take this_user's friend list, loop through each friend, and find this_user's index in the friend's friend list.


Student question: I want to free the memory in the heap but I am getting a memory leak. | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next;

Question: I want to free the memory in the heap but I am getting a memory leak.


Student question: Still getting a memory leak | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next;

Question: Still getting a memory leak


Student question: does this code have the same implementation as strncpy? | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { memset(dest, '\0', capacity); // Case 1: dest < src; cannot fully copy over, need to null terminate for (int i = 0; i < capacity && src[i] != '\0'; i++) { dest[i] = src[i]; } // Case 2: dest > src; have space left in dest // Already memset so n

Question: does this code have the same implementation as strncpy?


Student question: Does this code do what it is supposed to do: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { memset(dest, '\0', capacity); // Case 1: dest < src; cannot fully copy over, need to null terminate for (int i = 0; i < capacity && src[i] != '\0'; i++) { dest[i] = src[i]; } // Case 2: dest > src; have space left in dest // Already memset so n

Question: Does this code do what it is supposed to do: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated.


Student question: Does this code do what it is supposed to do: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { memset(dest, '\0', capacity); // Case 1: dest < src; cannot fully copy over, need to null terminate for (int i = 0; i < capacity && src[i] != '\0'; i++) { dest[i] = src[i]; } dest[-1] = '\0'; // Case 2: dest > src; have space left in dest // Al

Question: Does this code do what it is supposed to do: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated.


Student question: Does this code do what it is supposed to do: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { memset(dest, '\0', capacity); // Case 1: dest < src; cannot fully copy over, need to null terminate for (int i = 0; i < capacity; i++) { dest[i] = src[i]; } dest[-1] = '\0'; // Case 2: dest > src; have space left in dest // Already memset so no

Question: Does this code do what it is supposed to do: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated.


Goal: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. How can I fix the code? | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { memset(dest, '\0', capacity); // Case 1: dest < src; cannot fully copy over, need to null terminate for (int i = 0; i < capacity; i++) { dest[i] = src[i]; } dest[-1] = '\0'; // Case 2: dest > src; have space left in dest // Already memset so no


Goal: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. How can I fix the code? | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { memset(dest, '\0', capacity); // Case 1: dest < src; cannot fully copy over, need to null terminate for (int i = 0; i < capacity && src[i] != '\0'; i++) { dest[i] = src[i]; } dest[-1] = '\0'; // Case 2: dest > src; have space left in dest // Al


Goal: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. How can I fix the code? | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { memset(dest, '\0', capacity); // Case 1: dest < src; cannot fully copy over, need to null terminate for (int i = 0; i < capacity && src[i] != '\0'; i++) { dest[i] = src[i]; } dest[capacity] = '\0'; // Case 2: dest > src; have space left in dest


Student question: How do I add a null terminator to the end of the string? | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { memset(dest, '\0', capacity); // Case 1: dest < src; cannot fully copy over, need to null terminate for (int i = 0; i < capacity && src[i] != '\0'; i++) { dest[i] = src[i]; } dest[capacity] = '\0'; // Case 2: dest > src; have space left in dest

Question: How do I add a null terminator to the end of the string?


Student question: How do I add a null terminator to the end of the string? | Code context (simplify for kids): /* Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. You shoud read the man page to learn how strncpy works. NOTE: You must

Question: How do I add a null terminator to the end of the string?


Goal: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. Does this code do what it is supposed to do? | Code context (simplify for kids): /* Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. You shoud read the man page to learn how strncpy works. NOTE: You must


Student question: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. Does this code do what it is supposed to do? | Code context (simplify for kids): /* Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. You shoud read the man page to learn how strncpy works. NOTE: You must

Question: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. Does this code do what it is supposed to do?


Student question: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. Does this code do what it is supposed to do? | Code context (simplify for kids): /* Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. You shoud read the man page to learn how strncpy works. NOTE: You must

Question: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. Does this code do what it is supposed to do?


Goal: Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. | Code context (simplify for kids): /* Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. You shoud read the man page to learn how strncpy works. NOTE: You must


Code context (simplify for kids): /* Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. You shoud read the man page to learn how strncpy works. NOTE: You must


Student question: I am trying to make it such that only the parent can call fork(), but I am stuck. | Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int pid; for (int i = 0; i < iterations; i++) { if (i = 0) { int n = fork(); if (n != 0) { pid = getppid(); } } int n = fork(); if (n < 0) { pe

Question: I am trying to make it such that only the parent can call fork(), but I am stuck.


Student question: How do I modify this code so that only the parent can call fork()? | Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); for (int i = 0; i < iterations; i++) { int n = fork(); if (n < 0) { perror("fork"); exit(1); } printf("ppid = %d, pid = %d, i = %d\n", getppid(

Question: How do I modify this code so that only the parent can call fork()?


Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int pid; int n; for (int i = 0; i < iterations; i++) { // if (i = 0) { // int n = fork(); // if (n != 0) { // pid = getppid(); // } // } if (n


Goal: the new children do not create additional processes. Only the original parent calls fork. But currently, I get one extra fork | Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int pid; int n; for (int i = 0; i < iterations; i++) { if (n != 0) { n = fork(); } if (n < 0) { perror("fork"); exit(1); } printf("ppid = %d, p


Goal: I want to make sure only the original parent calls fork. | Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int pid; int n; for (int i = 0; i < iterations; i++) { if (n != 0) { n = fork(); } if (n < 0) { perror("fork"); exit(1); } printf("ppid = %d, p


Student question: I want to make it such that only child calls fork(). | Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); for (int i = 0; i < iterations; i++) { int n = fork(); if (n == 0) { n = fork(); } if (n < 0) { perror("fork"); exit(1); } printf("ppid = %d, p

Question: I want to make it such that only child calls fork().


Goal: I would like to make sure only child calls fork() but now it only calls it once and terminates when i = 2. So I only get one process from the child instead of 2. | Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int n; fork(); for (int i = 0; i < iterations; i++) { if (n == 0) { n = fork(); } if (n < 0) { perror("fork"); exit(1); } printf("ppid = %d, pi


Student question: I would like to make sure only child calls fork() but now it only calls it once and terminates when i = 2. So I only get one process from the child instead of 2. | Code context (simplify for kids): int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int n; fork(); for (int i = 0; i < iterations; i++) { if (n == 0) { n = fork(); } if (n < 0) { perror("fork"); exit(1); } printf("ppid = %d, pi

Question: I would like to make sure only child calls fork() but now it only calls it once and terminates when i = 2. So I only get one process from the child instead of 2.


Student question: what is the vaue of ptr | Code context (simplify for kids): char *ptr;

Question: what is the vaue of ptr


Student question: what is the value of s | Code context (simplify for kids): char s;

Question: what is the value of s


Question: logical or in c


Student question: how to initialize a empty string?

Question: how to initialize a empty string?


Student question: what is the value of s | Code context (simplify for kids): char s[3] ="";

Question: what is the value of s


Question: logical not in c


Question: what is not in C


Code context (simplify for kids): bool t = not false;


Student question: is operator not different than logical operator !

Question: is operator not different than logical operator !


Student question: how to declare a boolean type variable

Question: how to declare a boolean type variable


Question: value of false


Question: what type is false


Code context (simplify for kids): 0 and 0 == false;


Code context (simplify for kids): 0 || 1 == true;


Student question: format specifier for boolean type

Question: format specifier for boolean type


Student question: what is being compared when use == to compare two pointers

Question: what is being compared when use == to compare two pointers


Student question: what are switch stateemnts

Question: what are switch stateemnts


Student question: what does fclose return

Question: what does fclose return


Student question: how to initialize user.profile_pic to an empty array | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User;

Question: how to initialize user.profile_pic to an empty array


Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; User user1; char user1.profile_pic[20];


Goal: initialize user1.profile_pic to an empty array | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; User user1; char user1.profile_pic[20];


Goal: declare user1.profile_pic to be an array of char | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; User user1; char user1.profile_pic[20];


Question: value of true


Code context (simplify for kids): strlen(NULL);


Code context (simplify for kids): char s[3]; sprintf(s, "%s", NULL);