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
⌀ |
---|---|---|---|---|---|---|---|
63c648a65f004bf4898cfe6e | 2023-03-14T23:06:59.227Z | General Question | v2 | how to recursively evaluate | null | null | null |
63c648a65f004bf4898cfe6e | 2023-03-15T05:05:15.327Z | Explain Code | v2 | null |
void execute_action(Action *action) {
int r = fork();
if (r == 0) {
char *executable = malloc(sizeof(char) * MAXLINE);
args_to_string(action->args, buffer, MAXLINE);
fprintf(stdout, "%s\n", buffer);
execvp(action->args[0], action->args);
exit(0);
} else if (r > 0) {
wait(&status);
if (wait(&status) == -1) {
perror("wait");
}
if (WIFSIGNALED(status)) {
perror("fork");
exit(1);
}
} else {
perror("fork");
exit(1);
}
} | null | null |
63c648a65f004bf4898cfe6e | 2023-03-15T17:54:03.529Z | Help Write Code | v2 | null | null | null | split the string "main : fsd.o efsd.h fsdfs.c" into 2 strings, separated by the colon :, so "main" and "fsd.o efsd.h fsds.c" |
63c648a65f004bf4898cfe6e | 2023-03-15T20:02:30.292Z | Help Write Code | v2 | null | null | null | give me an example of using strtok |
63c648a65f004bf4898cfe6e | 2023-03-17T16:44:38.231Z | Help Fix Code | v2 | Write 100 integers (in binary) to a file with the name given by the command-line argument | #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
/* Write 100 integers (in binary) to a file with the name given by the command-line
* argument. You can write them from 0 to 99 or use random to write random numbers.
* This program creates a data file for use by the time_reads program.
*/
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: write_test_file filename\n");
exit(1);
}
FILE *fp;
if ((fp = fopen(argv[1], "w")) == NULL) {
perror("fopen");
exit(1);
}
// TODO: complete this program according its description above.
fclose(fp);
return 0;
} | null | null |
63c648a65f004bf4898cfe6e | 2023-03-17T16:45:44.917Z | Help Write Code | v2 | null | null | null | Write 100 integers (in binary) to a file with the name given by the command-line |
63c648a65f004bf4898cfe6e | 2023-03-22T00:58:05.039Z | Help Fix Code | v2 | why is this not working | int find_network_newline(const char *buf, int n) {
if (buf == NULL) {
return -1;
}
int index = 0;
for (int i = 0; i < n; i++) {
while (buf[i] != '\n') {
index++;
}
}
return index + 1;
} | null | null |
63c648a65f004bf4898cfe6e | 2023-03-30T01:50:06.719Z | Help Write Code | v2 | null | null | null | Makefile that compiles a program called friend_server. It must use the gcc flags -g, -std=gnu99, -Wall, and -Werror. |
63c648a65f004bf4898cfe6e | 2023-03-31T16:47:47.250Z | Help Fix Code | v2 | Modify function to return dynamically allocated strings in all cases (will need to change function signature) | /*
* Print the usernames of all users in the list starting at curr.
* Names should be printed to standard output, one per line.
*/
void list_users(const User *curr) {
printf("User List\n");
while (curr != NULL) {
printf("\t%s\n",curr->name);
curr = curr->next;
}
} | null | null |
63c648a65f004bf4898cfe6e | 2023-03-31T16:59:31.513Z | Help Write Code | v2 | null | null | null | how to allocate space for an array of size n of strings |
63c648a65f004bf4898cfe6e | 2023-03-31T18:22:42.313Z | Help Fix Code | v2 | how to use asprintf or snprintf to store curr->name in dynamically allocated strings | /*
* Print the usernames of all users in the list starting at curr.
* Names should be printed to standard output, one per line.
*/
void list_users(const User *curr) {
printf("User List\n");
while (curr != NULL) {
printf("\t%s\n",curr->name);
curr = curr->next;
}
} | null | null |
63c648a65f004bf4898cfe6e | 2023-03-31T18:29:23.136Z | Help Write Code | v2 | null | null | null | give an example using snprintf |
63c648a65f004bf4898cfe6e | 2023-03-31T20:13:23.259Z | Help Fix Code | v2 | i want to return arr but the function signature is different | char *list_users(const User *curr) {
printf("User List\n");
// keep track of number of users --> size of array of strings
int num_users = 0;
while (curr!= NULL) {
num_users++;
curr = curr->next;
}
// allocate space for arr
char **arr = malloc(sizeof(char *) * num_users);
// for loop to insert a user per index in the array
char *new_user;
for (int i = 0; i < num_users; i++) {
while (curr != NULL) {
new_user = snprintf("\t%s\n", strlen(curr->name), curr->name);
arr[i] = new_user;
curr = curr->next;
}
}
// return the array of strings
return *char;
} | null | null |
63c648a65f004bf4898cfe6e | 2023-03-31T21:13:53.862Z | General Question | v2 | how to import asprintf | null | null | null |
63c648a65f004bf4898cfe6e | 2023-03-31T21:16:27.302Z | General Question | v2 | fix error: error: implicit declaration of function ‘asprintf’; did you mean ‘vsprintf’? [-Werror=implicit-function-declaration]
89 | if (asprintf(&username, "%s\r\n", curr->name) == -1) { | null | null | null |
63c648a65f004bf4898cfe6e | 2023-03-31T21:47:46.957Z | Help Fix Code | v2 | change to asprintf() | char *list_users(const User *curr) {
printf("User List\n");
// keep track of number of users --> size of array of strings
int num_users = 0;
while (curr!= NULL) {
num_users++;
curr = curr->next;
}
// allocate space for arr
char **arr = malloc(sizeof(char *) * num_users);
// for loop to insert a user per index in the array
char *new_user;
for (int i = 0; i < num_users; i++) {
while (curr != NULL) {
new_user = snprintf("\t%s\n", strlen(curr->name), curr->name);
arr[i] = new_user;
curr = curr->next;
}
}
// return the array of strings
return *char;
}printf("------------------------------------------\n"); | null | null |
63c648a65f004bf4898cfe6e | 2023-03-31T21:49:04.800Z | Help Fix Code | v2 | use asprintf() instead | printf("------------------------------------------\n"); | null | null |
63c648a65f004bf4898cfe6e | 2023-04-04T02:53:11.829Z | General Question | v2 | Consider the sh script shifter.sh:
echo I live at $1 $2 $3.
shift
echo Now, I live at $0 $1 $2.
Suppose I run the script as follows:
sh shifter.sh 100 University Ave
What does it output? | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-04T02:55:52.626Z | Question from Code | v2 | What does running the following script "sh shifter.sh 100 University Ave" output | echo I live at $1 $2 $3.shift echo Now, I live at $0 $1 $2. | null | null |
63c648a65f004bf4898cfe6e | 2023-04-24T01:41:25.056Z | General Question | v2 | can multiple processes on a machine use the same port number to listen for connections | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-24T01:42:30.214Z | General Question | v2 | is it true that a SIGPIPE signal is sent when a process makes a write call to a closed socket or pipe | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-24T01:43:29.777Z | General Question | v2 | is it true that a SIGPIPE signal is sent when a process makes a write call to a closed socket or pipe | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-24T01:57:00.914Z | Help Write Code | v2 | null | null | null | write a shell script that adds every subdirectory of your current working directory to your PATH variables. note that the PATH variable requires an absolute path to each subdirectory. remember that the environment variable PWD stores the absolute path to the current working directory. do not recurse into subdirectories
|
63c648a65f004bf4898cfe6e | 2023-04-25T02:48:27.599Z | General Question | v2 | what is an active process whose parent has finished or terminated before it called | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-25T02:51:32.319Z | General Question | v2 | what function converts values from network to host byte order | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-25T02:53:17.129Z | General Question | v2 | which function gets data from the server | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-25T02:55:50.301Z | General Question | v2 | what or which function monitors the activity of a signal | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-25T02:59:09.329Z | General Question | v2 | which function raises a signal | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-25T03:00:13.030Z | General Question | v2 | how to specify a file descriptor to examine using a function | null | null | null |
63c648a65f004bf4898cfe6e | 2023-04-25T03:01:18.778Z | General Question | v2 | what function suspends execution until ALL children had terminated | null | null | null |
63c648a85f004bf4898cfe7d | 2023-01-26T00:32:04.095Z | Help Fix Code | v1 | null |
int check_sin(int *sin_array) {
//int arr[9];
int i;
int sum = 0;
if (sin_array[0] == 0) {
return 1;
}
for (i = 1; i <= 8; i += 2) {
sin_array[i] = sin_array[i] * 2;
if (sin_array[i] > 9) {
int x = sin_array[i] % 10;
int y = sin_array[i] / 10;
sin_array[i] = x + y;
}
}
for (i = 0; i < 9; i++) {
sum += sin_array[i];
}
if (sum % 10 == 0) {
return 0;
}
return 1;
}
| multiply every two index by two then add all the elements in the array if it is divisible by 10 then return 0 | null |
63c648a85f004bf4898cfe7d | 2023-02-12T04:38:53.842Z | General Question | v1 | You have two users as structs. Each have a friends array. How to link them together so that both point to each other.
| null | null | null |
63c648a85f004bf4898cfe7d | 2023-02-12T04:59:13.229Z | General Question | v1 | how to initialize an list to null | null | null | null |
63c648a85f004bf4898cfe7d | 2023-02-12T05:04:55.907Z | General Question | v1 | How to initialize a struct's array element to null | null | null | null |
63c648a85f004bf4898cfe7d | 2023-02-12T05:06:33.038Z | Help Fix Code | v1 | null | memset(new_user->friends, 'NULL', sizeof(new_user->friends)); | Make the struct new_user's friends array all NULL | null |
63c648a85f004bf4898cfe7d | 2023-02-12T05:09:29.516Z | General Question | v1 | 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. | null | null | null |
63c648a85f004bf4898cfe7d | 2023-02-12T05:10:16.930Z | General Question | v1 | 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. | null | null | null |
63c648a85f004bf4898cfe7d | 2023-02-12T05:30:02.929Z | Help Fix Code | v1 | null | user1->friends = friends_list1; | assign a friends_list1 array to the friends element of struct user1 | null |
63c648a85f004bf4898cfe7d | 2023-02-12T05:31:44.320Z | Help Fix Code | v1 | null | user1->friends[friends_list1]; | how to assign the friends_list1 array to user1 struct | null |
63c648a85f004bf4898cfe7d | 2023-02-12T05:32:40.742Z | Question from Code | v1 | how to assign an array called friends_list1 to user1 struct's friends component | user1->friendsfriends_list1; | null | null |
63c648a85f004bf4898cfe7d | 2023-02-12T05:33:37.309Z | Help Fix Code | v1 | null | user1->friends = friends_list1; | How to assign an array called friends_list1 to a struct user1's friends component | null |
63c648a85f004bf4898cfe7d | 2023-02-12T19:04:03.519Z | Help Fix Code | v1 | null | User *friends_list1[MAX_FRIENDS];
strcpy(user1->friends, friends_list1); | How to assign an array called friends_list1 to a struct user1's friends component | null |
63c648a85f004bf4898cfe7d | 2023-02-12T19:11:34.150Z | General Question | v1 | 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.
| null | null | null |
63c648a85f004bf4898cfe7d | 2023-02-12T22:51:30.267Z | Question from Code | v1 | How to do this | 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
int make_friends(const char *name1, const char *name2, User *head) {} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T01:56:22.966Z | Help Fix Code | v1 | null |
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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User friends_list1[MAX_FRIENDS];
User friends_list2[MAX_FRIENDS];
user1->friends[MAX_FRIENDS] = friends_list1;
user2->friends[MAX_FRIENDS] = friends_list2;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
if (head == NULL) {
strcpy(friends_list1[i].name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
} head = head->next;
}
return 0;
} | How to do this | null |
63c648a85f004bf4898cfe7d | 2023-02-13T01:57:41.537Z | Help Fix Code | v1 | null |
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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User friends_list1[MAX_FRIENDS];
User friends_list2[MAX_FRIENDS];
user1->friends[MAX_FRIENDS] = friends_list1;
user2->friends[MAX_FRIENDS] = friends_list2;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
if (head == NULL) {
strcpy(friends_list1[i].name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
} head = head->next;
}
return 0;
} | 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. | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:12:17.988Z | 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) {
//const User *curr = head;
while (head != NULL) {
if (strcmp(head->name,name) == 0) {
return (User *)head;
break;
}
head = head->next;
}
return NULL;
} | Is this right? | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:17:45.392Z | 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) {
User *curr = malloc(sizeof(User));
//const User *curr = head;
if (head == NULL) {
return NULL;
} else {
curr = (User *)head;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
return curr;
break;
}
curr = curr->next;
}
}
return NULL;
} | Is this right? | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:20:31.544Z | 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) {
const User *curr = malloc(sizeof(User));
//const User *curr = head;
if (head == NULL) {
return NULL;
} else {
curr = head;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
return (User *)curr;
break;
}
curr = curr->next;
}
}
return NULL;
} | Is this right | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:24:14.644Z | Help Fix Code | v1 | null | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
//strcpy(user1->name, name1);
//strcpy(user2->name, name2);
//struct user friends_list1[MAX_FRIENDS];
//struct user friends_list2[MAX_FRIENDS];
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1[MAX_FRIENDS];
User *friends_list2[MAX_FRIENDS];
user1->friends[MAX_FRIENDS] = *friends_list1;
user2->friends[MAX_FRIENDS] = *friends_list2;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i]->name, user2->name) == 0) {
return 1;
break;
} else {
if (head == NULL) {
strcpy(friends_list1[i]->name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
} head = head->next;
} | Is this right | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:25:50.424Z | Help Fix Code | v1 | null | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1[MAX_FRIENDS];
User *friends_list2[MAX_FRIENDS];
user1->friends[MAX_FRIENDS] = *friends_list1;
user2->friends[MAX_FRIENDS] = *friends_list2;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i]->name, user2->name) == 0) {
return 1;
break;
} else {
if (head == NULL) {
strcpy(friends_list1[i]->name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
} head = head->next;
} | Is this right? | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:38:59.731Z | General Question | v1 | How to print an array of pointers | null | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:41:48.595Z | Question from Code | v1 | whats wrong | User *friends_list1[MAX_FRIENDS] = malloc(sizeof(struct user)); | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:42:20.649Z | Help Fix Code | v1 | null | User *friends_list1[MAX_FRIENDS] = malloc(sizeof(struct user)); | How to fix this | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:43:19.315Z | Question from Code | v1 | I am getting a segmentation fault | user1->friends[MAX_FRIENDS] = *friends_list1;
user2->friends[MAX_FRIENDS] = *friends_list2; | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:43:51.583Z | Help Fix Code | v1 | null | user1->friends[MAX_FRIENDS] = *friends_list1;
user2->friends[MAX_FRIENDS] = *friends_list2; | How do I fix the segmentation fault | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:45:03.155Z | Help Fix Code | v1 | null | User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1[MAX_FRIENDS];
User *friends_list2[MAX_FRIENDS];
user1->friends[MAX_FRIENDS] = *friends_list1;
user2->friends[MAX_FRIENDS] = *friends_list2; | How do I fix the segmentation fault | null |
63c648a85f004bf4898cfe7d | 2023-02-13T02:47:17.309Z | Help Fix Code | v1 | null | User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1[MAX_FRIENDS];
User *friends_list2[MAX_FRIENDS];
friends_list1 = user1->friends[MAX_FRIENDS];
friends_list2 = user2->friends[MAX_FRIENDS]; | How to fix this and initialize the arrays | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:06:39.577Z | Question from Code | v1 | What are the steps to implement this function? | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) { | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:09:47.325Z | Question from Code | v1 | How do you check if the users are already friends? | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) { | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:14:08.004Z | Question from Code | v1 | Does this code (the part with the for loop) check if the users are already friends? | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
//strcpy(user1->name, name1);
//strcpy(user2->name, name2);
//struct user friends_list1[MAX_FRIENDS];
//struct user friends_list2[MAX_FRIENDS];
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
//friends_list1 = user1->friends[MAX_FRIENDS];
//friends_list2 = user2->friends[MAX_FRIENDS];
//user1->friends[MAX_FRIENDS] = *friends_list1;
//user2->friends[MAX_FRIENDS] = *friends_list2;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1; | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:19:02.856Z | Question from Code | v1 | Does the else part inside the for loop adds user2 to user1's friend list? | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
//strcpy(user1->name, name1);
//strcpy(user2->name, name2);
//struct user friends_list1[MAX_FRIENDS];
//struct user friends_list2[MAX_FRIENDS];
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
//friends_list1 = user1->friends[MAX_FRIENDS];
//friends_list2 = user2->friends[MAX_FRIENDS];
//user1->friends[MAX_FRIENDS] = *friends_list1;
//user2->friends[MAX_FRIENDS] = *friends_list2;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (curr == NULL) {
strcpy(friends_list1[i].name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:19:47.895Z | Question from Code | v1 | Does the else part inside the for loop adds user2 to user1's friend list? | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
//strcpy(user1->name, name1);
//strcpy(user2->name, name2);
//struct user friends_list1[MAX_FRIENDS];
//struct user friends_list2[MAX_FRIENDS];
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
//friends_list1 = user1->friends[MAX_FRIENDS];
//friends_list2 = user2->friends[MAX_FRIENDS];
//user1->friends[MAX_FRIENDS] = *friends_list1;
//user2->friends[MAX_FRIENDS] = *friends_list2;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (curr.next == NULL) {
strcpy(friends_list1[i].name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:20:29.163Z | Question from Code | v1 | How do I add user2 into user1's friend list? | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
//strcpy(user1->name, name1);
//strcpy(user2->name, name2);
//struct user friends_list1[MAX_FRIENDS];
//struct user friends_list2[MAX_FRIENDS];
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
//friends_list1 = user1->friends[MAX_FRIENDS];
//friends_list2 = user2->friends[MAX_FRIENDS];
//user1->friends[MAX_FRIENDS] = *friends_list1;
//user2->friends[MAX_FRIENDS] = *friends_list2;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (curr.next == NULL) {
strcpy(friends_list1[i].name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:23:32.735Z | Question from Code | v1 | How do I add a pointer to user2 into user1's friend list. You can do this by adding user2 to the first empty spot in user1->friends. | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
//strcpy(user1->name, name1);
//strcpy(user2->name, name2);
//struct user friends_list1[MAX_FRIENDS];
//struct user friends_list2[MAX_FRIENDS];
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
//friends_list1 = user1->friends[MAX_FRIENDS];
//friends_list2 = user2->friends[MAX_FRIENDS];
//user1->friends[MAX_FRIENDS] = *friends_list1;
//user2->friends[MAX_FRIENDS] = *friends_list2;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (curr.next == NULL) {
strcpy(friends_list1[i].name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:24:30.961Z | Question from Code | v1 | How do I add user2 to the first empty spot in user1->friends. | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
//strcpy(user1->name, name1);
//strcpy(user2->name, name2);
//struct user friends_list1[MAX_FRIENDS];
//struct user friends_list2[MAX_FRIENDS];
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
//friends_list1 = user1->friends[MAX_FRIENDS];
//friends_list2 = user2->friends[MAX_FRIENDS];
//user1->friends[MAX_FRIENDS] = *friends_list1;
//user2->friends[MAX_FRIENDS] = *friends_list2;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (curr.next == NULL) {
strcpy(friends_list1[i].name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:26:22.824Z | Help Fix Code | v1 | null | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
//strcpy(user1->name, name1);
//strcpy(user2->name, name2);
//struct user friends_list1[MAX_FRIENDS];
//struct user friends_list2[MAX_FRIENDS];
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
//friends_list1 = user1->friends[MAX_FRIENDS];
//friends_list2 = user2->friends[MAX_FRIENDS];
//user1->friends[MAX_FRIENDS] = *friends_list1;
//user2->friends[MAX_FRIENDS] = *friends_list2;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (curr.next == NULL) {
strcpy(friends_list1[i].name, user2->name);
//printf("%p", friends_list1[i]->name);
break;
}
}
curr = curr->next;
} | I want to use strcpy to copy the name of user2 into the first empty spot in user1->friends. | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:27:31.880Z | Help Fix Code | v1 | null | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (curr.next == NULL) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | How do I use strcpy to copy the name of user2 into the first empty spot in user1->friends. | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:31:03.962Z | Question from Code | v1 | How to find the first empty-spot in user1->friends? | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (curr.next == NULL) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:34:57.382Z | Question from Code | v1 | Does this add user2's name in user1's list atht he first empty spot? | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T03:36:30.445Z | Question from Code | v1 | Does this find the first empty-spot in user1->friends? | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T05:31:40.926Z | Explain Code | v1 | null | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T05:58:14.289Z | Help Fix Code | v1 | null | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | 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. | null |
63c648a85f004bf4898cfe7d | 2023-02-13T06:02:44.907Z | Help Fix Code | v1 | null | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | 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. | null |
63c648a85f004bf4898cfe7d | 2023-02-13T06:03:56.958Z | Question from Code | v1 | How to add the first user to the second user's friends list. | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T06:05:22.699Z | Question from Code | v1 | How to iterate through the second user's friends list | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T06:09:14.915Z | Question from Code | v1 | How to initialize a friends list for user1's friends | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T06:11:07.061Z | Question from Code | v1 | How to do this: iterating through the second user's friends list, and checking if the current spot is empty. If it is, you can add the first user to that spot. | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T06:12:20.053Z | Question from Code | v1 | How to iterate through the second user's friends list, and checking if the current spot is empty. If it is, you can add the first user to that spot. | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T06:13:03.276Z | Help Fix Code | v1 | null | /*
* 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User friends_list1 = user1->friends[MAX_FRIENDS];
User *friends_list2 = user2->friends[MAX_FRIENDS];
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i].name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i].name,"") == 0) {
strcpy(friends_list1[i].name, user2->name);
break;
}
}
curr = curr->next;
} | Iterate through the second user's friends list, and check if the current spot is empty. If it is, you can add the first user to that spot.
| null |
63c648a85f004bf4898cfe7d | 2023-02-13T17:22:23.797Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *curr;
User **friends_list1 = user1->friends;
User **friends_list2 = user2->friends;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(friends_list1[i]->name, user2->name) == 0) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i]->name,"") == 0) {
strcpy(friends_list1[i]->name, user2->name); //seg fault here
//printf("%p", friends_list1[i]->name);
break;
}
curr = curr->next;
}
}
return -1;
} | 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.
| null |
63c648a85f004bf4898cfe7d | 2023-02-13T17:24:47.692Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *curr;
User **friends_list1 = user1->friends;
User **friends_list2 = user2->friends;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (friends_list1[i] == user2) {
return 1;
break;
} else {
curr = head;
if (strcmp(friends_list1[i]->name,"") == 0) {
strcpy(friends_list1[i]->name, user2->name); //seg fault here
//printf("%p", friends_list1[i]->name);
break;
}
curr = curr->next;
}
}
return -1;
} | 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.
| null |
63c648a85f004bf4898cfe7d | 2023-02-13T17:37:35.001Z | Help Fix Code | v1 | null | * 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 same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
//User *user1 = malloc(sizeof(User));
//User *user2 = malloc(sizeof(User));
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
User *curr;
User **friends_list1 = user1->friends;
//User **friends_list2 = user2->friends;
if (user1 == user2) {
return 3;
}
if ( user1 == NULL || user2 == NULL) {
return 4;
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (friends_list1[i] == user2) {
return 1;
break;
} else {
curr = head;
if (friends_list1[i] == NULL) {
strcpy(friends_list1[i]->name, user2->name); //seg fault here
//printf("%p", friends_list1[i]->name);
break;
}
curr = curr->next;
}
}
return -1;
} | 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. | null |
63c648a85f004bf4898cfe7d | 2023-02-13T19:03:10.823Z | General Question | v1 | How to use time and ctime to display the time | null | null | null |
63c648a85f004bf4898cfe7d | 2023-02-13T19:09:53.732Z | Help Fix Code | v1 | null | time_t *post_time = malloc(sizeof(time_t));
time_t actual_time = time(post_time);
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
strcpy(new_post->contents, contents);
strcpy(new_post->date, ctime(&actual_time)); | assign the current time to the post->date | null |
63c648a85f004bf4898cfe7d | 2023-02-14T05:24:52.545Z | Question from Code | v1 | How to do this? | 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. | null | null |
63c648a85f004bf4898cfe7d | 2023-02-14T18:55:25.291Z | General Question | v1 | How to use perror | null | null | null |
63c648a85f004bf4898cfe7d | 2023-02-14T18:59:15.164Z | General Question | v1 | check the return value from malloc and terminate the program with a non-zero status if malloc fails. | null | null | null |
63c648a85f004bf4898cfe7d | 2023-03-07T03:49:36.321Z | General Question | v1 | How do we create a linked data structure with various structs | null | null | null |
63c648a85f004bf4898cfe7d | 2023-03-08T02:31:24.797Z | General Question | v1 | How to parse a makefile | null | null | null |
63c648a85f004bf4898cfe7d | 2023-03-09T04:03:33.764Z | General Question | v1 | Hoe to use strtok to parse a makefile | null | null | null |
63c648a85f004bf4898cfe7d | 2023-03-09T04:03:50.608Z | General Question | v1 | Give example to use strtok | null | null | null |
63c648a85f004bf4898cfe7d | 2023-03-09T04:56:13.803Z | General Question | v1 | How to use fopen when the only givne thing is a pointer to a FILE | null | null | null |
63c648a85f004bf4898cfe7d | 2023-03-09T05:52:57.601Z | Question from Code | v1 | Parse a makefile and create dependency with rule | char line[MAXLINE];
while (fgets(line, MAXLINE, fp) != NULL) {
if (is_comment_or_empty(line) == 0 && line[0] != '\n') {
token = strtok(line, " "); | null | null |
63c648a85f004bf4898cfe7d | 2023-03-09T05:55:48.240Z | Help Fix Code | v1 | null | Rule *parse_file(FILE *fp) {
// Implement this function and remove the stubbed return statement below.
fp = fopen("handout.mk", "r");
char *token;
char line[MAXLINE];
while (fgets(line, MAXLINE, fp) != NULL) {
if (is_comment_or_empty(line) == 0 && line[0] != '\n') {
token = strtok(line, " ");
}
}
return NULL;
}
void create_rule(char *target, Rule *head) {
Rule *new_rule = malloc(sizeof(Rule));
Rule *curr;
strcpy(new_rule->target, target);
new_rule->dependencies = NULL;
new_rule->actions = NULL;
new_rule->next_rule = NULL;
if (head == NULL) {
head = new_rule;
} else {
curr = head;
while (curr->next_rule != NULL) {
curr = curr->next_rule;
}
curr->next_rule = new_rule;
}
} | Parse the makefile and create a rule with the target name | null |
63c648a85f004bf4898cfe7d | 2023-03-09T05:57:32.693Z | Help Fix Code | v1 | null | Rule *parse_file(FILE *fp) {
// Implement this function and remove the stubbed return statement below.
fp = fopen("handout.mk", "r");
char *token;
char line[MAXLINE];
while (fgets(line, MAXLINE, fp) != NULL) {
if (is_comment_or_empty(line) == 0 && line[0] != '\n') {
token = strtok(line, " ");
}
}
} | Parse the makefile | null |
63c648a85f004bf4898cfe7d | 2023-03-09T06:05:04.940Z | Help Fix Code | v1 | null | Rule *parse_file(FILE *fp) {
// Implement this function and remove the stubbed return statement below.
fp = fopen("handout.mk", "r");
char *token;
Rule *new_rule = malloc(sizeof(Rule));
Dependency *new_dependency = malloc(sizeof(Dependency));
char line[MAXLINE];
while (fgets(line, MAXLINE, fp) != NULL) {
if (is_comment_or_empty(line) == 0 && line[0] != '\n') {
token = strtok(line, " ");
create_rule(token, new_rule);
}
}
} | Parse a makefile and create a rule from the target | null |
63c648a85f004bf4898cfe7d | 2023-03-09T20:41:51.589Z | Help Write Code | v2 | null | null | null | I want to parse a makefile and create a linked list of the rules |
63c648a85f004bf4898cfe7d | 2023-03-10T04:12:57.807Z | Help Write Code | v2 | null | null | null | checkpasswd.c 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. |
63c648a85f004bf4898cfe7d | 2023-03-10T05:23:12.978Z | Help Fix Code | v2 | checkpasswd.c 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. | int main(void) {
char user_id[MAXLINE];
char password[MAXLINE];
int status;
/* The user will type in a user name on one line followed by a password
on the next.
DO NOT add any prompts. The only output of this program will be one
of the messages defined above.
Please read the comments in validate carefully
*/
if(fgets(user_id, MAXLINE, stdin) == NULL) {
perror("fgets");
exit(1);
}
if(fgets(password, MAXLINE, stdin) == NULL) {
perror("fgets");
exit(1);
}
// TODO
if (strlen(user_id) > (MAX_PASSWORD + 1)) {
printf("%s",NO_USER);
exit(0);
}
if (strlen(password) > (MAX_PASSWORD + 1)) {
printf(INVALID);
exit(0);
}
int pipefd[2];
pipe(pipefd);
int result = fork();
if (result < 0) {
perror("fork");
exit(1);
}
else if (result == 0) {
dup2(pipefd[0], STDIN_FILENO);
dup2(pipefd[1], STDOUT_FILENO);
close(pipefd[0]);
close(pipefd[1]);
execl("./validate", "validate", NULL);
} else {
close(pipefd[0]);
write(pipefd[1], user_id, MAX_PASSWORD);
write(pipefd[1], password, MAX_PASSWORD);
close(pipefd[1]);
pid_t child_pid = wait(&status);
if (child_pid < 0) {
perror("wait");
exit(1);
}
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 0) {
printf("%s", SUCCESS);
} else if (WEXITSTATUS(status) == 2) {
printf("%s", INVALID);
} else if (WEXITSTATUS(status) == 3) {
printf("%s", NO_USER);
}
}
}
return 0;
} | null | null |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.