user_id
stringlengths
24
24
time
stringlengths
24
24
feature_type
stringclasses
5 values
feature_version
stringclasses
2 values
input_question
stringlengths
1
1.24k
input_code
stringlengths
2
18.5k
input_intention
stringlengths
1
2.48k
input_task_description
stringlengths
18
3.32k
63c647b05f004bf4898cf5d6
2023-03-12T20:55:38.337Z
Question from Code
v2
the code is meant to execute rules from a make file in parallel by having the parent create a child for each dependency. When compiled, the perror on line 29 runs. Why, and how do I fix this?
void parallel_eval(Rule *rule) { Dependency *dep_cur = rule->dependencies; int parentPID = getpid(); while (dep_cur != NULL) { // create a child proccess for each dependency if (parentPID == getpid()) { // parent int n = fork(); if (n < 0) { perror("Error: forking\n"); exit(1); } if (n == 0) { // child parallel_eval(dep_cur->rule); } } dep_cur = dep_cur->next_dep; } if (parentPID == getpid()) { int status; wait(&status); if (status < 0) { perror("Error: wait \n"); exit(1); } if (WIFEXITED(status)) { // checks id process exits normally if (WEXITSTATUS(status) != 0) { perror("Error: child exit incorrectly"); exit(1); } else if (WEXITSTATUS(status) == 1) { Action *act_cur = rule->actions; while (act_cur != NULL) { execute(act_cur); act_cur = act_cur->next_act; } } } } else { exit(compare_time(rule)); // check on this line ??? } }
null
null
63c647b05f004bf4898cf5d6
2023-03-12T23:48:43.411Z
General Question
v2
I tried logging in to a linux server and this error popped up on the terminal : PTY allocation request failed on channel 0. Any idea what caused this?
null
null
null
63c647b05f004bf4898cf5d6
2023-03-13T00:22:28.136Z
General Question
v2
I have a program that contains two functions. The first function creates a struct variable called other, but doesn't assign it a value. It calls the second function, which gets the struct other passed in through parameters. It creates the struct variable in the heap using malloc and assigns the passed in parameter other to the new struct. But when the second function returns, other goes back to NULL. Why?
null
null
null
63c647b05f004bf4898cf5d6
2023-03-13T00:23:08.959Z
General Question
v2
Question: I have a program that contains two functions. The first function creates a struct pointer called other, but doesn't assign it a value. It calls the second function, which gets the struct other passed in through parameters. It creates the struct variable in the heap using malloc and assigns the passed in parameter other to the new struct. But when the second function returns, other goes back to NULL. Why?
null
null
null
63c647b05f004bf4898cf5d6
2023-03-13T01:19:11.454Z
General Question
v2
I have a program that contains two functions. The first function creates a struct pointer called other and assigns it a value of NULL. It calls the second function, which gets the address of the struct pointer other passed in through its parameters. It creates the struct variable in the heap using malloc and assigns the new struct pointer to the passed in parameter. But when the second function returns, other goes back to NULL immediately. Why?
null
null
null
63c647b05f004bf4898cf5d6
2023-03-13T04:42:07.523Z
Question from Code
v2
if the file that rule refers to has never been compiled, what does this function return?
int compare_time(Rule *rule) { struct stat target_stat; Dependency *dep_cur = rule->dependencies; if (stat(rule->target, &target_stat) < 0) { // target file was never executed, so need to run actions return 1; } return 0; }
null
null
63c647b05f004bf4898cf5d6
2023-03-13T04:43:49.117Z
Question from Code
v2
assume the file that rule refers to has never been compiled. But the function keeps returning 1 when I run it. What could be causing the problem?
int compare_time(Rule *rule) { struct stat target_stat; Dependency *dep_cur = rule->dependencies; if (stat(rule->target, &target_stat) < 0) { // target file was never executed, so need to run actions return 1; } while (dep_cur != NULL) { struct stat check_stat; stat(dep_cur->rule->target, &check_stat); // set up struct for dependency struct timespec target_time = target_stat.st_mtim; // get last modified time from target struct timespec dep_time = check_stat.st_mtim; if (dep_time.tv_sec > target_time.tv_sec || dep_time.tv_nsec > target_time.tv_nsec) { // dependency is more up to date, need to execute actions return 1; } dep_cur = dep_cur->next_dep; } return 0; }
null
null
63c647b05f004bf4898cf5d6
2023-03-13T04:44:21.506Z
Question from Code
v2
Question: assume the file that rule refers to has never been compiled. But the function keeps returning 0 when I run it. What could be causing the problem?
int compare_time(Rule *rule) { struct stat target_stat; Dependency *dep_cur = rule->dependencies; if (stat(rule->target, &target_stat) < 0) { // target file was never executed, so need to run actions return 1; } while (dep_cur != NULL) { struct stat check_stat; stat(dep_cur->rule->target, &check_stat); // set up struct for dependency struct timespec target_time = target_stat.st_mtim; // get last modified time from target struct timespec dep_time = check_stat.st_mtim; if (dep_time.tv_sec > target_time.tv_sec || dep_time.tv_nsec > target_time.tv_nsec) { // dependency is more up to date, need to execute actions return 1; } dep_cur = dep_cur->next_dep; } return 0; }
null
null
63c647b05f004bf4898cf5d6
2023-03-17T05:10:12.141Z
Question from Code
v2
Why do I get this error: think the intro and conclusion of the internal validity section can be combined into the first and last examples. ?
struct sigaction action; action.sa_handler = handler; sigemptyset(&action.sa_mask); action.sa_flags = 0; sigaction(SIGPROF, &action, NULL);
null
null
63c647b05f004bf4898cf5d6
2023-03-17T05:14:18.730Z
Question from Code
v2
Why do I get this error: "incomplete type is not allowed" for the variable "action"?
struct sigaction action; action.sa_handler = handler; sigemptyset(&action.sa_mask); action.sa_flags = 0; sigaction(SIGPROF, &action, NULL);
null
null
63c647b05f004bf4898cf5d6
2023-03-24T23:43:01.618Z
Help Write Code
v2
null
null
null
Variable x has been assigned a digit between 1 and 10. Write a shell command to calculate x minus 1 and display the result to standard output.
63c647b05f004bf4898cf5d6
2023-03-24T23:43:27.522Z
General Question
v2
Variable x has been assigned a digit between 1 and 10. How do I write a shell command to calculate x minus 1 and display the result to standard output.
null
null
null
63c647b05f004bf4898cf5d6
2023-03-24T23:46:42.729Z
General Question
v2
Variable x has been assigned a digit between 1 and 10. Write a sh shell command to calculate x minus 1 and display the result to standard output.
null
null
null
63c647b05f004bf4898cf5d6
2023-03-24T23:47:01.216Z
Help Write Code
v2
null
null
null
Variable x has been assigned a digit between 1 and 10. Write an sh shell command to calculate x minus 1 and display the result to standard output.
63c647b05f004bf4898cf5d6
2023-03-24T23:57:42.335Z
General Question
v2
I'm trying to use expr in shell command but when I use * for multiplication, I get an error. What's the problem?
null
null
null
63c647b05f004bf4898cf5d6
2023-03-25T00:53:17.449Z
General Question
v2
if i call read(fd, &buf, BUF_SIZE); does read concatonate onto buf or does it overwrite buf?
null
null
null
63c647b05f004bf4898cf5d6
2023-03-25T01:54:47.138Z
Question from Code
v2
should malloc be assigned sizeof(char) * num_read or sizeof(char) * (1 + num_read) ?
int num_read = read(fd, &buf, BUF_SIZE); buf[num_read] = '\0'; users[client_index].username = malloc(sizeof(char) * num_read);
null
null
63c647b05f004bf4898cf5d6
2023-04-05T02:22:44.445Z
Question from Code
v2
after using malloc, do I have to explicitly set the name[strlen(username)] = '\0' ?
char *name = malloc(sizeof(char) * (strlen(username) + 1)); strncpy(client->username, name, strlen(name));
null
null
63c647b05f004bf4898cf5d6
2023-04-05T02:27:23.884Z
Question from Code
v2
the code is supposed to create a string name from the contents of username and allocate memory in the heap. However, when I run the code through gdb, name = "". What is causing this error?
char *name = malloc(sizeof(char) * (strlen(username) + 1)); name[strlen(username)] = '\0'; strncpy(client->username, name, strlen(name) + 1);
null
null
63c647b05f004bf4898cf5d6
2023-04-05T02:27:58.905Z
Question from Code
v2
the code is supposed to create a string name from the contents of username and allocate memory in the heap. However, when I run the code through gdb, name = "". What is causing this error?
char *name = malloc(sizeof(char) * (strlen(username) + 1)); name[strlen(username)] = '\0';
null
null
63c647b05f004bf4898cf5d6
2023-04-05T02:29:39.004Z
Question from Code
v2
I want to save the contents of username in the heap using malloc. is this correct?
client->username = malloc(sizeof(char) * (strlen(username) + 1)); client->username[strlen(username)] = '\0'; strncpy(client->username, username, strlen(name) + 1);
null
null
63c647b05f004bf4898cf5d6
2023-04-05T02:30:26.430Z
Question from Code
v2
I want to save the contents of username in the heap using malloc. is this correct?
client->username = malloc(sizeof(char) * (strlen(username) + 1)); client->username[strlen(username)] = '\0'; strncpy(client->username, username, strlen(username) + 1);
null
null
63c647b05f004bf4898cf5d6
2023-04-05T03:01:46.818Z
Question from Code
v2
the code is supposed to take a string and tokenize it such that if the input string = "hello world here I am", cmd_argv[0] = "hello" cmd_argv[1] = "world" cmd_argv[2] = "here I am" and if input string = "hello world" cmd_argv[0] = "hello" cmd_argv[1] = "world" cmd_argv[2] = NULL but for the second example, I still get 3 values. What is the error?
int cmd_argc = 0; char *next_token = strtok(cmd, DELIM); while (next_token != NULL && cmd_argc < 3) { cmd_argv[cmd_argc] = next_token; cmd_argc++; if (cmd_argc == 2) { char *rest = strtok(NULL, ""); cmd_argv[cmd_argc - 1] = strndup(cmd_argv[cmd_argc - 1], rest - cmd_argv[cmd_argc - 1] - 1); // ??? cmd_argv[cmd_argc] = rest; cmd_argc++; } next_token = strtok(NULL, DELIM); }
null
null
63c647b05f004bf4898cf5d6
2023-04-05T03:04:19.272Z
General Question
v2
if I write "print var" and gdb outputs "0x0", is that the equivalent to var = NULL?
null
null
null
63c647b05f004bf4898cf5d6
2023-04-05T03:21:38.802Z
Question from Code
v2
why does this code give me a buffer overflow error?
int len = 1; const User *current = curr; while (current != NULL) { len += strlen(current->name) + 2; current = current->next; } char *buf = malloc(sizeof(char) * len); int index = 0; int add = 0; while (curr != NULL) { add = snprintf(buf + index, len - index, "%s\r\n", curr->name); if (add >= len - len) { // buffer overflow (shouldn't happen though) perror("Buffer overflow"); exit(1); } index += add; curr = curr->next; } buf[len - 1] = '\0'; return buf;
null
null
63c647b05f004bf4898cf5d6
2023-04-05T03:33:11.564Z
Question from Code
v2
if the date is jan. 1, 2021, what is the value of len?
int len = strlen(asctime(localtime(post->date)))
null
null
63c647b05f004bf4898cf5d6
2023-04-23T15:23:35.174Z
Question from Code
v2
Does the malloc assignment statement only allocate enough room for the entire string s (except null terminator) or just enough space for a string pointer?
char *s = "hello world"; char *t = malloc(sizeof(s));
null
null
63c647b05f004bf4898cf5d6
2023-04-25T21:00:18.157Z
Help Write Code
v2
null
null
null
The file /u/ajr/t contains zero or more integers, one per line. Write shell command to output the sum of all of these integers plus 10. (For example, if the file is empty, the output would be 10, or if it contains ‘‘2\n3\n’’ the output would be 15.)
63c647b15f004bf4898cf5e0
2023-02-15T17:06:46.815Z
Help Fix Code
v1
null
User *find_user(const char *name, const User *head) { // traverse the linked list and check each user for a matching name // return the pointer if they exist User *node = head; while (node->next != NULL) { if (strncmp(node->name, name, MAX_NAME) == 0) { return node; } node = node->next; } return NULL; }
traverse a linked list of User objects and return the pointer to the user with the given name, or NULL if it does not exist
null
63c647b15f004bf4898cf5e0
2023-02-15T17:12:31.694Z
Help Fix Code
v1
null
User *find_user(const char *name, const User *head) { // traverse the linked list and check each user for a matching name // return the pointer if they exist User *node = head; while (node->next != NULL) { if (strncmp(node->name, name, MAX_NAME) == 0) { return node; } node = node->next; } // check the last element of the linked list if (strncmp(node->name, name, MAX_NAME) == 0) { return node; } return NULL; }
traverse a linked list of User objects and return the pointer to the user with the given name, or NULL if it does not exist
null
63c647b15f004bf4898cf5e0
2023-02-15T17:14:35.086Z
Help Fix Code
v1
null
User *find_user(const char *name, const User *head) { // traverse the linked list and check each user for a matching name // return the pointer if they exist User *node = head; while (node != NULL) { if (strncmp(node->name, name, MAX_NAME) == 0) { return node; } node = node->next; } return NULL; }
traverse a linked list of User objects and return the pointer to the user with the given name, or NULL if it does not exist
null
63c647b15f004bf4898cf5e0
2023-02-15T17:19:57.130Z
Help Fix Code
v1
null
void list_users(const User *curr) { // traverse the linked list and print each name using printf User *node = curr; while (node != NULL) { printf("%s\n", node->name); node = node->next; } }
traverse a linked list of User objects and print each User's name and a new line
null
63c647b15f004bf4898cf5e0
2023-02-15T17:20:54.321Z
Help Fix Code
v1
null
void list_users(const User *curr) { // traverse the linked list and print each name using printf const User *node = curr; while (node != NULL) { printf("%s\n", node->name); node = node->next; } }
traverse a linked list of User objects and print each User's name and a new line
null
63c647b15f004bf4898cf5e0
2023-02-15T18:40:14.686Z
Help Fix Code
v1
null
int i = 3; printf(i);
print an integer
null
63c647b15f004bf4898cf5e0
2023-02-15T22:08:32.459Z
Help Fix Code
v1
null
User *find_user(const char *name, const User *head) { // traverse the linked list and check each user for a matching name // return the pointer if they exist const User *node = head; while (node != NULL) { if (strncmp(node->name, name, MAX_NAME) == 0) { return (User *) node; } node = node->next; } return NULL; }
return a pointer to a User object if a User with name exists in a linked list of Users, and NULL if a User with name does not exist in the linked list of Users.
null
63c647b15f004bf4898cf5e0
2023-03-14T20:11:10.051Z
Help Fix Code
v2
add action_pt to the end of the actions list of the current rule
Action *last_act = curr_rule->actions; while (last_act->next_act != NULL) { last_act = last_act->next_act; } last_act->next_act = action_pt;
null
null
63c647b15f004bf4898cf5e0
2023-03-15T07:50:53.924Z
Help Fix Code
v2
determine if a file exists
int file_exists(char *filename) { FILE *f = fopen(filename, "r"); if (f != NULL) { fclose(f); return 1; } return 0; }
null
null
63c647b25f004bf4898cf5e5
2023-01-31T15:10:35.021Z
General Question
v1
How does malloc work?
null
null
null
63c647b25f004bf4898cf5e5
2023-01-31T15:38:36.138Z
Help Fix Code
v1
null
char **build_month_list() { char jan[] = "Januray"; char feb[] = "February"; char mar[] = "March"; char **array = malloc(sizeof(jan) * 3); array[0] = jan; array[1] = feb; array[2] = mar; return array; } int main() { // For part 3: Once you've implemented build_month_list, uncomment this code. char **months = build_month_list(); for(int i = 0; i < 3; i++) { printf("%s ", months[i]); } printf("\n"); for(int i = 0; i < 3; i++) { months[i][3] = '\0'; printf("%s ", months[i]); } printf("\n"); return 0; }
Prints: January February March Jan Feb Mar
null
63c647b25f004bf4898cf5e5
2023-01-31T15:46:36.676Z
Help Fix Code
v1
null
char **build_month_list() { char *jan = malloc(sizeof(char * 8)); char *feb = malloc(sizeof(char * 9)); char *mar = malloc(sizeof(char * 6)); strcpy(jan, "January"); strcpy(feb, "February"); strcpy(mar, "March"); char **array = malloc(sizeof(jan) * 3); array[0] = jan; array[1] = feb; array[2] = mar; return array; } int main() { // For part 3: Once you've implemented build_month_list, uncomment this code. char **months = build_month_list(); for(int i = 0; i < 3; i++) { printf("%s ", months[i]); } printf("\n"); for(int i = 0; i < 3; i++) { months[i][3] = '\0'; printf("%s ", months[i]); } printf("\n"); return 0; }
Prints: January February March Jan Feb Mar
null
63c647b35f004bf4898cf5ef
2023-01-17T20:20:55.400Z
General Question
v1
what kind of question do i ask you
null
null
null
63c647b35f004bf4898cf5ef
2023-01-17T20:21:55.024Z
General Question
v1
how to initialize a string in c
null
null
null
63c647b35f004bf4898cf5ef
2023-01-17T20:31:13.818Z
General Question
v1
what type is result[0] in chat *result[2];
null
null
null
63c647b35f004bf4898cf5ef
2023-01-26T11:10:16.106Z
General Question
v1
how can i initialize a pointer to a struct
null
null
null
63c647b55f004bf4898cf603
2023-01-28T18:57:24.379Z
Explain Code
v1
null
#include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *, char *); // testing to see if edits are working //jan 26 int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } // TODO: Process command line arguments. // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. return 0; }
null
null
63c647b55f004bf4898cf603
2023-01-28T18:58:52.762Z
Help Write Code
v1
null
null
null
process command line arguments
63c647b55f004bf4898cf603
2023-01-29T02:39:13.651Z
Help Write Code
v1
null
null
null
extract each digit of an integer
63c647b55f004bf4898cf603
2023-01-29T14:41:19.554Z
General Question
v1
how to define a string literal
null
null
null
63c647b55f004bf4898cf603
2023-01-29T21:49:00.769Z
Explain Code
v1
null
// TODO: Implement populate_array /* * Convert a 9 digit int to a 9 element int array. */ int populate_array(int sin, int *sin_array) { int digits = 0; int num = sin; while(num != 0){ num = num / 10; digits += 1; } if(digits != 9){ return 1; } int position = 0; while(sin != 0){ sin_array[position] = sin % 10; position += 1; sin = sin / 10; } return 0; } // TODO: Implement check_sin /* * Return 0 if the given sin_array is a valid SIN, and 1 otherwise. */ int check_sin(int *sin_array) { // total starts off at 0 int sin_total = 0; // loop over it for (int position = 0; position < 8; position++){ // if at an even position just multiply that by 1 if(position % 2 == 0){ sin_total += sin_array[position]; } // if not, multiply it by 2 else{ if (((2 * sin_array[position]) / 10) != 0){ int temp = sin_array[position]; while(temp != 0){ sin_total += temp % 10; temp = temp / 10; } } else{ sin_total += (2 * sin_array[position]); } // if the product is only one digit // need to add some code to handle if it's 2 digits. // in this case add the two digits together AND THEN add that to the total. } } // if the total is divisible by 10 it is a valid SIN if (sin_total % 10 == 0){ return 0; } // else, it's NOT a valid SIN else{ return 1; } }
null
null
63c647b55f004bf4898cf603
2023-01-29T22:33:16.120Z
Explain Code
v1
null
// TODO: Implement populate_array /* * Convert a 9 digit int to a 9 element int array. */ int populate_array(int sin, int *sin_array) { int digits = 0; int position = 0; while(sin != 0){ sin_array[position] = sin % 10; digits += 1; position += 1; sin = sin / 10; } if (digits != 9){ return 1; } else{ return 0; } } // TODO: Implement check_sin /* * Return 0 if the given sin_array is a valid SIN, and 1 otherwise. */ int check_sin(int *sin_array) { // total starts off at 0 int sin_total = 0; // loop over it for (int position = 0; position < 8; position++){ // if at an even position just multiply that by 1 if(position % 2 == 0){ sin_total += sin_array[position]; } // if not, multiply it by 2 else{ if (((2 * sin_array[position]) / 10) != 0){ int temp = sin_array[position]; while(temp != 0){ sin_total += temp % 10; temp = temp / 10; } } else{ sin_total += (2 * sin_array[position]); } // if the product is only one digit // need to add some code to handle if it's 2 digits. // in this case add the two digits together AND THEN add that to the total. } } // if the total is divisible by 10 it is a valid SIN if (sin_total % 10 == 0){ return 0; } // else, it's NOT a valid SIN else{ return 1; } }
null
null
63c647b55f004bf4898cf603
2023-01-29T22:37:32.858Z
Explain Code
v1
null
int populate_array(int sin, int *sin_array) { int digits = 0; int position = 0; while(sin != 0){ sin_array[position] = sin % 10; digits += 1; position += 1; sin = sin / 10; } if (digits != 9){ return 1; } else{ return 0; } } int check_sin(int *sin_array) { int sin_total = 0; for (int position = 0; position < 8; position++){ if(position % 2 == 0){ sin_total += sin_array[position]; } else{ if (((2 * sin_array[position]) / 10) != 0){ int temp = sin_array[position]; while(temp != 0){ sin_total += temp % 10; temp = temp / 10; } } else{ sin_total += (2 * sin_array[position]); } } } if (sin_total % 10 == 0){ return 0; } else{ return 1; } }
null
null
63c647b55f004bf4898cf603
2023-01-29T23:30:25.280Z
General Question
v1
how do I check if an element of a character array is 'a', 'b', or 'c'
null
null
null
63c647b55f004bf4898cf603
2023-01-29T23:37:03.573Z
Question from Code
v1
is this the right way to check if characters match
if(required[i] == 'r' || required[i] == 'w' || required[i] == 'x'){ if (required[i] != permissions_field[i]){ return 1; } }
null
null
63c647b55f004bf4898cf603
2023-01-29T23:37:32.499Z
Question from Code
v1
is this checking the memory addresses
if(required[i] == 'r' || required[i] == 'w' || required[i] == 'x'){ if (required[i] != permissions_field[i]){ return 1; } }
null
null
63c647b55f004bf4898cf603
2023-01-29T23:38:11.635Z
Question from Code
v1
what operators are being used in the if statements
if(required[i] == 'r' || required[i] == 'w' || required[i] == 'x'){ if (required[i] != permissions_field[i]){ return 1; } }
null
null
63c647b55f004bf4898cf603
2023-01-30T00:25:53.894Z
Help Write Code
v1
null
null
null
take two 9-element character arrays as arguments and returns an integer. (The prototype for this function is in the starter code.) The first array will represent the permission field of a file and the second will represent the permissions that are required. The function will return 0 if the file has all the required permissions and 1 otherwise. The arrays do not have to be identical for a 0 to be returned. For example, if the first array holds the characters rwxr-x--- and the second array holds the characters r-x------, the function should return 0.
63c647b55f004bf4898cf603
2023-01-30T00:30:07.402Z
Explain Code
v1
null
if(required[i] == 'r' || required[i] == 'w' || required[i] == 'x'){ if (required[i] != permissions_field[i]){ return 1; } } // TODO: Implement a helper named check_permissions that matches the prototype below. //int check_permissions(char *, char *); int check_permissions(char *permissions_field, char *required){ //takes the permissions and required //if it has all the required permissions //check where in required it's not a dash and make sure the // corresponding spot in permissions_field matches //return 0 //else //return 1 //go through required //if the ith element in the array is r or w or x, then // compare it to the array at the same position in permissins_field //if the position in both is equal then keep going //if not then the positions do not match so return 1 //loop through required, an array of 9 characters int i; for (i = 0; i < 9; i++){ // check it if(required[i] != '-'){ if (required[i] != permissions_field[i]){ return 1; } } return 0; } }
null
null
63c647b55f004bf4898cf603
2023-01-30T00:32:37.989Z
Help Write Code
v1
null
null
null
// TODO: Process command line arguments. // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. //check to make sure it's a regular file and not directory //check size // check permisions (or vice versa)
63c647b55f004bf4898cf603
2023-01-30T00:33:29.698Z
Help Write Code
v1
null
null
null
Process command line arguments. Call check_permissions as part of your solution to count the files to compute and print the correct value.
63c647b55f004bf4898cf603
2023-01-30T01:04:11.659Z
Help Write Code
v1
null
null
null
assign the variable p to be the permissions of the ls-l output
63c647b55f004bf4898cf603
2023-01-30T23:11:11.841Z
General Question
v1
how do I add together the two digits of an integer
null
null
null
63c647b55f004bf4898cf603
2023-01-30T23:47:49.133Z
Explain Code
v1
null
/* * Convert a 9 digit int to a 9 element int array. */ int populate_array(int sin, int *sin_array) { int position = 8; while(sin != 0){ sin_array[position] = sin % 10; sin = sin / 10; position -= 1; } return 0; }
null
null
63c647b55f004bf4898cf603
2023-01-30T23:49:17.011Z
Help Fix Code
v1
null
/* * Convert a 9 digit int to a 9 element int array. */ int populate_array(int sin, int *sin_array) { int position = 8; while(sin != 0){ sin_array[position] = sin % 10; sin = sin / 10; position -= 1; } return 0; }
turn 9 digit integer into 9 digit array, in same order. return 1 if the integer is less than 100000000
null
63c647b55f004bf4898cf603
2023-01-30T23:51:23.998Z
Help Write Code
v1
null
null
null
get the sum of the two digits of an integer between 10 and 20
63c647b55f004bf4898cf603
2023-01-30T23:53:23.844Z
Help Fix Code
v1
null
int check_sin(int *sin_array) { int sin_total = 0; for(int i = 8; i>=0; i--){ if(i % 2 == 0){ sin_total += sin_array[i]; } else{ if(sin_array[i] < 5){ sin_total += (sin_array[i] * 2); } else{ int temp1 = sin_array[i] % 2; int temp2 = sin_array[i] / 10; int add = temp1 + temp2; sin_total += add; // int temp = sin_array[i]; // while(temp != 0){ // sin_total += (temp % 10); // temp = temp / 10; } } } if((sin_total % 10) != 0){ return 1; } return 0; }
if int i is even, add sin_array[I] to sin_total if int i is ODD, add the digits of sin_array at the ith position to sin_total
null
63c647b55f004bf4898cf603
2023-01-31T02:47:45.595Z
Help Write Code
v1
null
null
null
Write a loop which traverses a linked list starting at front and prints the value of each node in the list. Separate each value with a space.
63c647b55f004bf4898cf603
2023-02-14T16:53:08.396Z
Help Fix Code
v1
null
/* * Create a new user with the given name. Insert it at the tail of the list * of users whose head is pointed to by *user_ptr_add. * * Return: * - 0 if successful * - 1 if a user by this name already exists in this list * - 2 if the given name cannot fit in the 'name' array * (don't forget about the null terminator) */ int create_user(const char *name, User **user_ptr_add) { User *curr = *user_ptr_add; // go thru the LL basically and check that no user with name already exists while(curr != NULL){ if (strcmp(curr->name, name) == 0){ return 1; } } // if the given name can't fit the name array return -2 if(strlen(name) >= MAX_NAME){ return -2; } // now that it's been determined that this User CAN be created: User *new_user = malloc(sizeof(User)); strcpy(new_user->name, name); new_user->next = NULL; if(*user_ptr_add == NULL){ *user_ptr_add = new_user; } else{ curr = *user_ptr_add; while(curr->next != NULL){ curr = curr->next; } curr->next = new_user; } return 0; }
create a new user with the given name and insert it at the tail of the list of users whose head is pointed to by *user_ptr_add
null
63c647b55f004bf4898cf603
2023-02-14T16:54:55.080Z
Help Fix Code
v1
null
/* * Create a new user with the given name. Insert it at the tail of the list * of users whose head is pointed to by *user_ptr_add. * * Return: * - 0 if successful * - 1 if a user by this name already exists in this list * - 2 if the given name cannot fit in the 'name' array * (don't forget about the null terminator) */ int create_user(const char *name, User **user_ptr_add) { User *curr = *user_ptr_add; // go thru the LL basically and check that no user with name already exists while(curr != NULL){ if (strcmp(curr->name, name) == 0){ return 1; } } // if the given name can't fit the name array return -2 if(strlen(name) >= MAX_NAME){ return -2; } // now that it's been determined that this User CAN be created: User *new_user = malloc(sizeof(User)); strcpy(new_user->name, name); new_user->next = NULL; if(*user_ptr_add == NULL){ *user_ptr_add = new_user; } else{ curr = *user_ptr_add; while(curr->next != NULL){ curr = curr->next; } curr = curr->next; curr->next = new_user; } return 0; }
* Create a new user with the given name. Insert it at the tail of the list * of users whose head is pointed to by *user_ptr_add. * * Return: * - 0 if successful * - 1 if a user by this name already exists in this list * - 2 if the given name cannot fit in the 'name' array * (don't forget about the null terminator)
null
63c647b55f004bf4898cf603
2023-02-14T16:58:04.718Z
Help Fix Code
v1
null
/* * Create a new user with the given name. Insert it at the tail of the list * of users whose head is pointed to by *user_ptr_add. * * Return: * - 0 if successful * - 1 if a user by this name already exists in this list * - 2 if the given name cannot fit in the 'name' array * (don't forget about the null terminator) */ int create_user(const char *name, User **user_ptr_add) { User *curr = *user_ptr_add; // go thru the LL basically and check that no user with name already exists while(curr != NULL){ if (strcmp(curr->name, name) == 0){ return 1; } } // if the given name can't fit the name array return -2 if(strlen(name) >= MAX_NAME){ return -2; } // now that it's been determined that this User CAN be created: User *new_user = malloc(sizeof(User)); strcpy(new_user->name, name); new_user->next = NULL; if(*user_ptr_add == NULL){ *user_ptr_add = new_user; } else{ curr = *user_ptr_add; while(curr->next != NULL){ curr = curr->next; } curr->next = new_user; } return 0; }
* Create a new user with the given name. Insert it at the tail of the list * of users whose head is pointed to by *user_ptr_add. * * Return: * - 0 if successful * - 1 if a user by this name already exists in this list * - 2 if the given name cannot fit in the 'name' array * (don't forget about the null terminator) */
null
63c647b55f004bf4898cf603
2023-02-14T17:01:12.345Z
Question from Code
v1
does this code effectively go through the entire linked list
// go thru the LL basically and check that no user with name already exists while(curr != NULL){ if (strcmp(curr->name, name) == 0){ return 1; curr = curr->next; } }
null
null
63c647b55f004bf4898cf603
2023-02-14T17:02:24.273Z
Help Fix Code
v1
null
// go thru the LL basically and check that no user with name already exists while(curr != NULL){ if (strcmp(curr->name, name) == 0){ return 1; } curr = curr->next; }
make this check every node in the linked list
null
63c647b55f004bf4898cf603
2023-02-15T01:04:44.101Z
Help Fix Code
v1
null
User *find_user(const char *name, const User *head) { // start at the first user object in the linked list User *current = head; // check if the name of every user is this name while(current->next != NULL){ // if it is return a pointer to the user if (strcmp(current->name, name) == 0){ return *current; } } // if that never happens, return NULL return NULL; }
go through the linked list and return a pointer to the User with the given name
null
63c647b55f004bf4898cf603
2023-02-15T01:05:41.616Z
Explain Code
v1
null
User *find_user(const char *name, const User *head) { // start at the first user object in the linked list User *current = head; // check if the name of every user is this name while(current->next != NULL){ // if it is return a pointer to the user if (strcmp(current->name, name) == 0){ return current; } } // if that never happens, return NULL return NULL; }
null
null
63c647b55f004bf4898cf603
2023-02-15T01:12:09.177Z
Question from Code
v1
how do I Cast a const User *
/* * Return a pointer to the user with this name in * the list starting with head. Return NULL if no such user exists. * * NOTE: You'll likely need to cast a (const User *) to a (User *) * to satisfy the prototype without warnings. */ User *find_user(const char *name, const User *head) { // start at the first user object in the linked list const User *current = head; // check if the name of every user is this name while(current->next != NULL){ // if it is return a pointer to the user if (strcmp(current->name, name) == 0){ // User *pointer_to_match = current; // return pointer_to_match; return current; } } // if that never happens, return NULL return NULL; }
null
null
63c647b55f004bf4898cf603
2023-02-15T01:14:12.423Z
Explain Code
v1
null
/* * Return a pointer to the user with this name in * the list starting with head. Return NULL if no such user exists. * * NOTE: You'll likely need to cast a (const User *) to a (User *) * to satisfy the prototype without warnings. */ User *find_user(const char *name, const User *head) { // start at the first user object in the linked list const User *current = head; // check if the name of every user is this name while(current->next != NULL){ // if it is return a pointer to the user if (strcmp(current->name, name) == 0){ // User *pointer_to_match = current; // return pointer_to_match; return current; } } // if that never happens, return NULL return NULL; }
null
null
63c647b55f004bf4898cf603
2023-02-15T01:15:20.941Z
Help Fix Code
v1
null
/* * Return a pointer to the user with this name in * the list starting with head. Return NULL if no such user exists. * * NOTE: You'll likely need to cast a (const User *) to a (User *) * to satisfy the prototype without warnings. */ User *find_user(const char *name, const User *head) { // start at the first user object in the linked list const User *current = head; // check if the name of every user is this name while(current->next != NULL){ // if it is return a pointer to the user if (strcmp(current->name, name) == 0){ // User *pointer_to_match = current; // return pointer_to_match; return current; } } // if that never happens, return NULL return NULL; }
cast a (const User *) to a (User *) to satisfy prototype without warnings
null
63c647b55f004bf4898cf603
2023-02-15T13:25:44.682Z
Help Fix Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { // find the two users User *u1 = find_user(name1, head); User *u2 = find_user(name2, head); // make sure that neither of them is NULL aka they both do exist if(u1 == NULL || u2 == NULL){ return 4; } // check that the same user has not been passed in twice if (strcmp(name1, name2) == 0){ return 3; } //check that they are not already friends // iterate through each list of pointers to friends (aka other users) // not covering the case where they're already friends for (int i = 0; i < MAX_FRIENDS; i++) { if (u1->friends[i] != NULL) { if (strcmp(u2->friends[i]->name, name2) == 0) { return 1; } } } // last, check that neither has max friends // check that u1 doesnt int u1_friends = 0; int u2_friends = 0; while(u1->friends[u1_friends] != NULL){ u1_friends += 1; } while(u2->friends[u2_friends] != NULL){ u2_friends += 1; } if (u1_friends >= MAX_FRIENDS || u2_friends >= MAX_FRIENDS){ return 2; } // go thorugh each array of pointers friends to find the first empty spot // based on the checks already done, we know that there is at least one empty spot // CERTAIN that i will find an empty spot before reaching the end of the list // thats why the while loop stopping conditions are what they are int spot1 = 0; int spot2 = 0; while(u1->friends[spot1] != NULL){ spot1 ++; } while(u2->friends[spot2] != NULL){ spot2 ++; } // once the first empty spot in both users' friends have been found // add u2 to the first empty spot in the friends array of u1 // not working when a user already has at least one friend!!!! u1->friends[spot1] = u2; // vice versa u2->friends[spot2] = u1; return 0; }
if it gets to the end of the code, it is not adding each user to one another's array of pointers to friends (other users)
null
63c647b55f004bf4898cf603
2023-02-15T13:29:32.034Z
Explain Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { // find the two users User *u1 = find_user(name1, head); User *u2 = find_user(name2, head); // make sure that neither of them is NULL aka they both do exist if(u1 == NULL || u2 == NULL){ return 4; } // check that the same user has not been passed in twice if (strcmp(name1, name2) == 0){ return 3; } //check that they are not already friends // iterate through each list of pointers to friends (aka other users) // not covering the case where they're already friends for (int i = 0; i < MAX_FRIENDS; i++) { if (u1->friends[i] != NULL) { if (strcmp(u2->friends[i]->name, name2) == 0) { return 1; } } } // last, check that neither has max friends // check that u1 doesnt int u1_friends = 0; int u2_friends = 0; while(u1->friends[u1_friends] != NULL){ u1_friends += 1; } while(u2->friends[u2_friends] != NULL){ u2_friends += 1; } if (u1_friends >= MAX_FRIENDS || u2_friends >= MAX_FRIENDS){ return 2; } // go thorugh each array of pointers friends to find the first empty spot // based on the checks already done, we know that there is at least one empty spot // CERTAIN that i will find an empty spot before reaching the end of the list // thats why the while loop stopping conditions are what they are int spot1 = 0; int spot2 = 0; while(u1->friends[spot1] != NULL){ spot1 ++; } while(u2->friends[spot2] != NULL){ spot2 ++; } // once the first empty spot in both users' friends have been found // add u2 to the first empty spot in the friends array of u1 // not working when a user already has at least one friend!!!! u1->friends[spot1] = u2; // vice versa u2->friends[spot2] = u1; return 0; }
null
null
63c647b55f004bf4898cf603
2023-02-15T13:32:03.799Z
Explain Code
v1
null
/* * Make a new post from 'author' to the 'target' user, * containing the given contents, IF the users are friends. * * Insert the new post at the *front* of the user's list of posts. * * 'contents' is a pointer to heap-allocated memory - you do not need * to allocate more memory to store the contents of the post. * * Return: * - 0 on success * - 1 if users exist but are not friends * - 2 if either User pointer is NULL */ int make_post(const User *author, User *target, char *contents) { // check that both users exist // check that the users are friends // once both those things have been checked, create the new post Post *new_post = malloc(sizeof(Post)); return 0; }
null
null
63c647b55f004bf4898cf603
2023-02-15T13:34:52.997Z
Help Fix Code
v1
null
/* * Make a new post from 'author' to the 'target' user, * containing the given contents, IF the users are friends. * * Insert the new post at the *front* of the user's list of posts. * * 'contents' is a pointer to heap-allocated memory - you do not need * to allocate more memory to store the contents of the post. * * Return: * - 0 on success * - 1 if users exist but are not friends * - 2 if either User pointer is NULL */ int make_post(const User *author, User *target, char *contents) { // check that both users exist // check that the users are friends // once both those things have been checked, create the new post Post *new_post = malloc(sizeof(Post)); return 0; }
make a new post from author to target if the users both exist and are friends. if both these conditions are met, make a new post
null
63c647b55f004bf4898cf603
2023-02-15T14:24:25.674Z
Help Fix Code
v1
null
void list_users(const User *curr) { // start at the curr user User *curr_user = (User *) curr; // keep going through the linked list till the end is reached while(curr_user != NULL){ // THIS LINE BELOW IS A PROBLEM! printf(stdout, "%s\n", curr_user->name); //print_user(curr); curr_user = curr_user->next; } }
/* * Print the usernames of all users in the list starting at curr. * Names should be printed to standard output, one per line. */
null
63c647b55f004bf4898cf603
2023-02-15T14:44:27.107Z
Help Fix Code
v1
null
/* * Return a pointer to the user with this name in * the list starting with head. Return NULL if no such user exists. * * NOTE: You'll likely need to cast a (const User *) to a (User *) * to satisfy the prototype without warnings. */ User *find_user(const char *name, const User *head) { // start at the first user object in the linked list User *current = (User *) head; //const User *current = head; // check if the name of every user is this name while(current->next != NULL){ // if it is return a pointer to the user if (strcmp(current->name, name) == 0){ // User *pointer_to_match = current; // return pointer_to_match; return (User*)current; } current = current->next; } // if that never happens, return NULL return NULL; }
not finding the user if it is the last one in the linked list
null
63c647b55f004bf4898cf603
2023-02-15T14:53:29.764Z
Help Fix Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { // find the two users User *u1 = find_user(name1, head); User *u2 = find_user(name2, head); // make sure that neither of them is NULL aka they both do exist if(u1 == NULL || u2 == NULL){ return 4; } // check that the same user has not been passed in twice if (strcmp(name1, name2) == 0){ return 3; } // check that neither has max friends // check that u1 doesnt int u1_friends = 0; int u2_friends = 0; while(u1->friends[u1_friends] != NULL){ u1_friends += 1; } while(u2->friends[u2_friends] != NULL){ u2_friends += 1; } if (u1_friends >= MAX_FRIENDS || u2_friends >= MAX_FRIENDS){ return 2; } //check that they are not already friends // iterate through each list of pointers to friends (aka other users) // not covering the case where they're already friends for (int i = 0; i < MAX_FRIENDS; i++) { if (u1->friends[i] != NULL) { if (strcmp(u1->friends[i]->name, name2) == 0) { return 1; } } if (u2->friends[i] != NULL){ if(strcmp(u2->friends[i]->name, name1) == 0){ return 1; } } } // go thorugh each array of pointers friends to find the first empty spot // based on the checks already done, we know that there is at least one empty spot // CERTAIN that i will find an empty spot before reaching the end of the list // thats why the while loop stopping conditions are what they are int spot1 = 0; int spot2 = 0; while(u1->friends[spot1] != NULL){ spot1 ++; } while(u2->friends[spot2] != NULL){ spot2 ++; } // once the first empty spot in both users' friends have been found // add u2 to the first empty spot in the friends array of u1 // not working when a user already has at least one friend!!!! u1->friends[spot1] = u2; // vice versa u2->friends[spot2] = u1; return 0; }
don't give a segmentation fault when I give a user a second friend
null
63c647b55f004bf4898cf603
2023-02-15T14:55:54.447Z
Explain Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { // find the two users User *u1 = find_user(name1, head); User *u2 = find_user(name2, head); // make sure that neither of them is NULL aka they both do exist if(u1 == NULL || u2 == NULL){ return 4; } // check that the same user has not been passed in twice if (strcmp(name1, name2) == 0){ return 3; } // check that neither has max friends // check that u1 doesnt int u1_friends = 0; int u2_friends = 0; while(u1->friends[u1_friends] != NULL){ u1_friends += 1; } while(u2->friends[u2_friends] != NULL){ u2_friends += 1; } if (u1_friends >= MAX_FRIENDS || u2_friends >= MAX_FRIENDS){ return 2; } //check that they are not already friends // iterate through each list of pointers to friends (aka other users) // not covering the case where they're already friends for (int i = 0; i < MAX_FRIENDS; i++) { if (u1->friends[i] != NULL) { if (strcmp(u1->friends[i]->name, name2) == 0) { return 1; } } if (u2->friends[i] != NULL){ if(strcmp(u2->friends[i]->name, name1) == 0){ return 1; } } } // go thorugh each array of pointers friends to find the first empty spot // based on the checks already done, we know that there is at least one empty spot // CERTAIN that i will find an empty spot before reaching the end of the list // thats why the while loop stopping conditions are what they are int spot1 = 0; int spot2 = 0; while(u1->friends[spot1] != NULL){ spot1 ++; } while(u2->friends[spot2] != NULL){ spot2 ++; } // once the first empty spot in both users' friends have been found // add u2 to the first empty spot in the friends array of u1 // not working when a user already has at least one friend!!!! u1->friends[spot1] = u2; // vice versa u2->friends[spot2] = u1; return 0; }
null
null
63c647b55f004bf4898cf603
2023-02-15T21:35:00.694Z
Help Fix Code
v1
null
/* * Print a user profile. * For an example of the required output format, see the example output * linked from the handout. * Return: * - 0 on success. * - 1 if the user is NULL. */ int print_user(const User *user) { // check that the user exists User *print_me = (User *) user; if (print_me == NULL){ return 1; } printf("pfp here\n"); printf("Name: %s\n", print_me->name); printf("------------------------------------------\n"); printf("Friends:\n"); // go through the friends of this user for(int i = 0; i < MAX_FRIENDS; i++){ // make sure that the user at the index is not NULL if(print_me->friends[i] != NULL){ // print the name of that friend (who is a User) printf("%s\n", print_me->friends[i]->name); } } printf("------------------------------------------\n"); printf("Posts: \n"); if(print_me->first_post != NULL){ Post *curr_post = print_me->first_post; while(curr_post != NULL){ // do stuff to it here!!!!!! printf("From: %s\n", curr_post->author); printf("Date: %s\n", ctime(curr_post->date)); printf("%s\n", curr_post->contents); curr_post = curr_post->next; } } return 0; } /* * Make a new post from 'author' to the 'target' user, * containing the given contents, IF the users are friends. * * Insert the new post at the *front* of the user's list of posts. * * 'contents' is a pointer to heap-allocated memory - you do not need * to allocate more memory to store the contents of the post. * * Return: * - 0 on success * - 1 if users exist but are not friends * - 2 if either User pointer is NULL */ int make_post(const User *author, User *target, char *contents) { User *a = (User *) author; User *t = target; // check that both users exist if(a == NULL || t == NULL){ return 2; } // CHECK THAT THEY ARE FRIENDS AND RETURN 1 IF NOT int are_friends = check_if_friends(a, t); if(are_friends == 0){ return 1; } // now that it has been verified that they both exist and are friends // create the new post time_t *post_time = malloc(sizeof(time_t)); *post_time = time(post_time); Post *new_post = malloc(sizeof(Post)); strcpy(new_post->author, a->name); new_post->contents = contents; new_post->date = post_time; new_post->next = NULL; // add it in // if the target user does not have any posts just make it the first post if(target->first_post == NULL){ target->first_post = new_post; } else { // otherwise // store a pointer to the rest of the linked list Post *rest_of_posts = target->first_post->next; // make the target's first post point to the memory address of the new_post target->first_post = new_post; // make new_post next point to the rest of the linked list of posts new_post->next = rest_of_posts; // return 0 upon successfully making the post } return 0; }
when print_user is called, make sure all of the user's posts are printed not just the most recent one
null
63c647b55f004bf4898cf603
2023-02-15T21:38:35.189Z
Help Fix Code
v1
null
/* * Make a new post from 'author' to the 'target' user, * containing the given contents, IF the users are friends. * * Insert the new post at the *front* of the user's list of posts. * * 'contents' is a pointer to heap-allocated memory - you do not need * to allocate more memory to store the contents of the post. * * Return: * - 0 on success * - 1 if users exist but are not friends * - 2 if either User pointer is NULL */ int make_post(const User *author, User *target, char *contents) { User *a = (User *) author; User *t = target; // check that both users exist if(a == NULL || t == NULL){ return 2; } // CHECK THAT THEY ARE FRIENDS AND RETURN 1 IF NOT int are_friends = check_if_friends(a, t); if(are_friends == 0){ return 1; } // now that it has been verified that they both exist and are friends // create the new post time_t *post_time = malloc(sizeof(time_t)); *post_time = time(post_time); Post *new_post = malloc(sizeof(Post)); strcpy(new_post->author, a->name); new_post->contents = contents; new_post->date = post_time; new_post->next = NULL; // add it in // if the target user does not have any posts just make it the first post if(target->first_post == NULL){ target->first_post = new_post; } else { // otherwise // store a pointer to the rest of the linked list Post *rest_of_posts = target->first_post->next; // make the target's first post point to the memory address of the new_post target->first_post = new_post; // make new_post next point to the rest of the linked list of posts new_post->next = rest_of_posts; // return 0 upon successfully making the post } return 0; }
properly store the new post at the beginning of the linked list without losing the rest of the linked list
null
63c647b55f004bf4898cf603
2023-02-15T21:45:13.546Z
Help Write Code
v1
null
null
null
how do I print the contents of a file
63c647b55f004bf4898cf603
2023-02-15T21:48:03.553Z
Help Fix Code
v1
null
/* * Print a user profile. * For an example of the required output format, see the example output * linked from the handout. * Return: * - 0 on success. * - 1 if the user is NULL. */ int print_user(const User *user) { // check that the user exists User *print_me = (User *) user; if (print_me == NULL){ return 1; } printf("pfp here\n"); FILE *pfp = fopen(print_me->profile_pic); printf("Name: %s\n", print_me->name); printf("------------------------------------------\n"); printf("Friends:\n"); // go through the friends of this user for(int i = 0; i < MAX_FRIENDS; i++){ // make sure that the user at the index is not NULL if(print_me->friends[i] != NULL){ // print the name of that friend (who is a User) printf("%s\n", print_me->friends[i]->name); } } printf("------------------------------------------\n"); printf("Posts: \n"); if(print_me->first_post != NULL){ Post *curr_post = print_me->first_post; while(curr_post != NULL){ // do stuff to it here!!!!!! printf("From: %s\n", curr_post->author); printf("Date: %s\n", ctime(curr_post->date)); printf("%s\n", curr_post->contents); curr_post = curr_post->next; } } return 0; }
print the pfp (profile pic) in the beginning of the code. open the file containing it and print its contents.
null
63c647b55f004bf4898cf603
2023-02-15T22:18:18.323Z
Help Fix Code
v1
null
int delete_user(const char *name, User **user_ptr_del) { // find the user with that username User *delete_me = find_user(name, *user_ptr_del); // if it does not exist, return 1 if (delete_me == NULL){ return 1; } // once established that the user that u wanna delete does indeed exist in the // list pointed to by *user_ptr_delete, start the process of DELETING it // start by removing the user from its friends lists of friends // remove the posts of the user that's being deleted if(delete_me->first_post != NULL){ Post *curr_post = delete_me->first_post; while(curr_post != NULL){ Post *next_post = curr_post->next; free(curr_post->date); free(curr_post->contents); free(curr_post); curr_post = next_post; } } // go through the friends of the user we are deleting for(int index = 0; index < MAX_FRIENDS; index++){ // go to every spot in it User *friend_of_deleted = delete_me->friends[index]; // if there's a friend in that spot, gotta go delete delete_me from its friends array if(friend_of_deleted != NULL){ // go through its list of friends and find delete_me, then change it to null for(int j = 0; j < MAX_FRIENDS; j++){ if(friend_of_deleted->friends[j] == delete_me){ friend_of_deleted->friends[j] = NULL; break; } } } } // go through the linked list of users and delete the user u want to delete // special case if the user we want to delete IS at the beginning of the LL if(*user_ptr_del == delete_me){ User *after = delete_me->next; *user_ptr_del = after; } // start at the beginning of the Linked List User *curr_user = *user_ptr_del; // find the node aka the user you want to delete while(curr_user->next != delete_me){ curr_user = curr_user->next; } // once delete_me has been found, store the link to the node (user) after it User *after_deleted = curr_user->next->next; // make the node before the one being deleted point to the user after the one being deleted curr_user->next = after_deleted; // free memory for the node (user) that's being deleted aka delete_me free(delete_me); return 0; }
/* * From the list pointed to by *user_ptr_del, delete the user * with the given name. * Remove the deleted user from any lists of friends. * * Return: * - 0 on success. * - 1 if a user with this name does not exist. */ make sure there are no memory leaks
null
63c647b55f004bf4898cf603
2023-02-15T22:20:43.376Z
Help Fix Code
v1
null
int delete_user(const char *name, User **user_ptr_del) { // find the user with that username User *delete_me = find_user(name, *user_ptr_del); // if it does not exist, return 1 if (delete_me == NULL){ return 1; } // once established that the user that u wanna delete does indeed exist in the // list pointed to by *user_ptr_delete, start the process of DELETING it // start by removing the user from its friends lists of friends // remove the posts of the user that's being deleted if(delete_me->first_post != NULL){ Post *curr_post = delete_me->first_post; while(curr_post != NULL){ Post *next_post = curr_post->next; free(curr_post->date); free(curr_post->contents); free(curr_post); curr_post = next_post; } } // go through the friends of the user we are deleting for(int index = 0; index < MAX_FRIENDS; index++){ // go to every spot in it User *friend_of_deleted = delete_me->friends[index]; // if there's a friend in that spot, gotta go delete delete_me from its friends array if(friend_of_deleted != NULL){ // go through its list of friends and find delete_me, then change it to null for(int j = 0; j < MAX_FRIENDS; j++){ if(friend_of_deleted->friends[j] == delete_me){ friend_of_deleted->friends[j] = NULL; break; } } } } // go through the linked list of users and delete the user u want to delete // special case if the user we want to delete IS at the beginning of the LL if(*user_ptr_del == delete_me){ User *after = delete_me->next; *user_ptr_del = after; } // start at the beginning of the Linked List User *curr_user = *user_ptr_del; // find the node aka the user you want to delete while(curr_user->next != delete_me){ curr_user = curr_user->next; } // once delete_me has been found, store the link to the node (user) after it User *after_deleted = curr_user->next->next; // make the node before the one being deleted point to the user after the one being deleted curr_user->next = after_deleted; // free memory for the node (user) that's being deleted aka delete_me free(delete_me); return 0; }
free the posts of this user
null
63c647b55f004bf4898cf603
2023-02-15T22:23:01.803Z
Help Write Code
v1
null
null
null
start from the first node of a linked list and free every node
63c647b55f004bf4898cf603
2023-03-03T19:49:14.552Z
Help Fix Code
v1
null
#include <stdio.h> #include <unistd.h> #include <stdlib.h> /* * Modify the program so that new children do not create additional processes */ 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(), getpid(), i); } return 0; }
new children should not create additional processes
null
63c647b55f004bf4898cf603
2023-03-12T17:19:00.784Z
Explain Code
v2
null
main : linked_list.o main.o gcc - Wall - g - std = gnu99 - o main linked_list.o main .o main.o : main.c linked_list.h gcc - Wall - g - std = gnu99 - c main .c linked_list.o : linked_list.c linked_list.h gcc - Wall - g - std = gnu99 - c linked_list.c #notice that this target has no dependencies clean : rm - f main rm - f linked_list.o rm - f main.o
null
null
63c647b55f004bf4898cf603
2023-03-12T17:27:54.206Z
Help Write Code
v2
null
null
null
write code to parse through the makefile and make a linked data structure
63c647b55f004bf4898cf603
2023-03-14T01:18:01.368Z
Question from Code
v2
What does the program print to stderr if the user presses Ctrl+C at the moment when the program is at position C?
int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); x += 2; fprintf(stderr, "outside %d", x); return 0; }
null
null
63c647b55f004bf4898cf603
2023-03-14T01:20:00.760Z
Explain Code
v2
null
int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); x += 2; fprintf(stderr, "outside %d", x); return 0; }
null
null
63c647b55f004bf4898cf603
2023-03-14T18:54:38.312Z
General Question
v2
explain strtok to me
null
null
null
63c647b55f004bf4898cf603
2023-03-15T18:27:17.138Z
Help Write Code
v2
null
null
null
turn an action line of a makefile into a char **args
63c647b55f004bf4898cf603
2023-03-15T18:29:25.088Z
Help Fix Code
v2
create a new struct action_node
typedef struct action_node { char **args; // An array of strings suitable to be passed to execvp struct action_node *next_act; } Action; /* Create a new action node. * Return a pointer to this action node. */ Action *create_action_node(char **args){ Action *new_action_node = malloc(sizeof(Action)); return new_action_node; }
null
null
63c647b55f004bf4898cf603
2023-03-15T18:30:36.379Z
Help Write Code
v2
null
null
null
assign the args to the new action node