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
⌀ |
---|---|---|---|---|---|---|---|
63c6479f5f004bf4898cf545 | 2023-01-26T23:37:56.194Z | Question from Code | v1 | what parameters should be passed to full_array and result? | int *build_array(char **strs, int size) {
int *arr = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
arr[i] = strtol(strs[i], NULL, 10);
}
return arr;
}
int **split_array(const int *s, int length) {
int **arrays = malloc(sizeof(int *) * 2);
int *arr_even = malloc(sizeof(int) * ((length / 2) - (length % 2)));
int *arr_odd = malloc(sizeof(int) * ((length / 2) + (length % 2)));
int even_count = 0;
int odd_count = 0;
for (int i = 0; i < length; i++) {
if (i % 2 == 0) {
arr_even[even_count] = s[i];
even_count++;
} else {
arr_odd[odd_count] = s[i];
odd_count++;
}
}
arrays[0] = arr_even;
arrays[1] = arr_odd;
return arrays;
}
int main(int argc, char **argv) {
/* Replace the comments in the next two lines with the appropriate
arguments. Do not add any additional lines of code to the main
function or make other changes.
*/
int *full_array = build_array(argv[1], argc - 1);
int **result = split_array(full_array, sizeof(full_array));
printf("Original array:\n");
for (int i = 0; i < argc - 1; i++) {
printf("%d ", full_array[i]);
}
printf("\n");
printf("result[0]:\n");
for (int i = 0; i < argc / 2; i++) {
printf("%d ", result[0][i]);
}
printf("\n");
printf("result[1]:\n");
for (int i = 0; i < (argc - 1) / 2; i++) {
printf("%d ", result[1][i]);
}
printf("\n");
free(full_array);
free(result[0]);
free(result[1]);
free(result);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-01-26T23:40:49.509Z | Question from Code | v1 | what stops this from compiling | int *build_array(char **strs, int size) {
int *arr = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
arr[i] = strtol(strs[i], NULL, 10);
}
return arr;
}
int **split_array(const int *s, int length) {
int **arrays = malloc(sizeof(int *) * 2);
int *arr_even = malloc(sizeof(int) * ((length / 2) - (length % 2)));
int *arr_odd = malloc(sizeof(int) * ((length / 2) + (length % 2)));
int even_count = 0;
int odd_count = 0;
for (int i = 0; i < length; i++) {
if (i % 2 == 0) {
arr_even[even_count] = s[i];
even_count++;
} else {
arr_odd[odd_count] = s[i];
odd_count++;
}
}
arrays[0] = arr_even;
arrays[1] = arr_odd;
return arrays;
}
int main(int argc, char **argv) {
/* Replace the comments in the next two lines with the appropriate
arguments. Do not add any additional lines of code to the main
function or make other changes.
*/
int *full_array = build_array(argv[1], argc - 1);
int **result = split_array(full_array, sizeof(full_array));
printf("Original array:\n");
for (int i = 0; i < argc - 1; i++) {
printf("%d ", full_array[i]);
}
printf("\n");
printf("result[0]:\n");
for (int i = 0; i < argc / 2; i++) {
printf("%d ", result[0][i]);
}
printf("\n");
printf("result[1]:\n");
for (int i = 0; i < (argc - 1) / 2; i++) {
printf("%d ", result[1][i]);
}
printf("\n");
free(full_array);
free(result[0]);
free(result[1]);
free(result);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-01-26T23:44:33.006Z | Question from Code | v1 | what is the type of argv[1] | int *build_array(char **strs, int size) {
int *arr = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
arr[i] = strtol(strs[i], NULL, 10);
}
return arr;
}
int **split_array(const int *s, int length) {
int **arrays = malloc(sizeof(int *) * 2);
int *arr_even = malloc(sizeof(int) * ((length / 2) - (length % 2)));
int *arr_odd = malloc(sizeof(int) * ((length / 2) + (length % 2)));
int even_count = 0;
int odd_count = 0;
for (int i = 0; i < length; i++) {
if (i % 2 == 0) {
arr_even[even_count] = s[i];
even_count++;
} else {
arr_odd[odd_count] = s[i];
odd_count++;
}
}
arrays[0] = arr_even;
arrays[1] = arr_odd;
return arrays;
}
int main(int argc, char **argv) {
/* Replace the comments in the next two lines with the appropriate
arguments. Do not add any additional lines of code to the main
function or make other changes.
*/
int *full_array = build_array(argv[1], argc - 1);
int **result = split_array(full_array, sizeof(full_array));
printf("Original array:\n");
for (int i = 0; i < argc - 1; i++) {
printf("%d ", full_array[i]);
}
printf("\n");
printf("result[0]:\n");
for (int i = 0; i < argc / 2; i++) {
printf("%d ", result[0][i]);
}
printf("\n");
printf("result[1]:\n");
for (int i = 0; i < (argc - 1) / 2; i++) {
printf("%d ", result[1][i]);
}
printf("\n");
free(full_array);
free(result[0]);
free(result[1]);
free(result);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-01-26T23:46:30.548Z | Question from Code | v1 | will this compile | int *build_array(char **strs, int size) {
int *arr = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
arr[i] = strtol(strs[i], NULL, 10);
}
return arr;
}
int **split_array(const int *s, int length) {
int **arrays = malloc(sizeof(int *) * 2);
int *arr_even = malloc(sizeof(int) * ((length / 2) - (length % 2)));
int *arr_odd = malloc(sizeof(int) * ((length / 2) + (length % 2)));
int even_count = 0;
int odd_count = 0;
for (int i = 0; i < length; i++) {
if (i % 2 == 0) {
arr_even[even_count] = s[i];
even_count++;
} else {
arr_odd[odd_count] = s[i];
odd_count++;
}
}
arrays[0] = arr_even;
arrays[1] = arr_odd;
return arrays;
}
int main(int argc, char **argv) {
/* Replace the comments in the next two lines with the appropriate
arguments. Do not add any additional lines of code to the main
function or make other changes.
*/
int *full_array = build_array(argv[1], argc - 1);
int **result = split_array(full_array, sizeof(full_array));
printf("Original array:\n");
for (int i = 0; i < argc - 1; i++) {
printf("%d ", full_array[i]);
}
printf("\n");
printf("result[0]:\n");
for (int i = 0; i < argc / 2; i++) {
printf("%d ", result[0][i]);
}
printf("\n");
printf("result[1]:\n");
for (int i = 0; i < (argc - 1) / 2; i++) {
printf("%d ", result[1][i]);
}
printf("\n");
free(full_array);
free(result[0]);
free(result[1]);
free(result);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-01-26T23:53:01.319Z | Question from Code | v1 | will this compile | int *build_array(char **strs, int size) {
int *arr = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
arr[i] = strtol(strs[i], NULL, 10);
}
return arr;
}
int **split_array(const int *s, int length) {
int **arrays = malloc(sizeof(int *) * 2);
int *arr_even = malloc(sizeof(int) * ((length / 2) - (length % 2)));
int *arr_odd = malloc(sizeof(int) * ((length / 2) + (length % 2)));
int even_count = 0;
int odd_count = 0;
for (int i = 0; i < length; i++) {
if (i % 2 == 0) {
arr_even[even_count] = s[i];
even_count++;
} else {
arr_odd[odd_count] = s[i];
odd_count++;
}
}
arrays[0] = arr_even;
arrays[1] = arr_odd;
return arrays;
}
int main(int argc, char **argv) {
/* Replace the comments in the next two lines with the appropriate
arguments. Do not add any additional lines of code to the main
function or make other changes.
*/
int *full_array = build_array(argv, argc - 1);
int **result = split_array(full_array, sizeof(full_array));
printf("Original array:\n");
for (int i = 0; i < argc - 1; i++) {
printf("%d ", full_array[i]);
}
printf("\n");
printf("result[0]:\n");
for (int i = 0; i < argc / 2; i++) {
printf("%d ", result[0][i]);
}
printf("\n");
printf("result[1]:\n");
for (int i = 0; i < (argc - 1) / 2; i++) {
printf("%d ", result[1][i]);
}
printf("\n");
free(full_array);
free(result[0]);
free(result[1]);
free(result);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-01-27T00:40:58.419Z | Question from Code | v1 | how can i make sure that memory is allocated and free correctly | int *build_array(char **strs, int size) {
int *arr = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
arr[i] = strtol(strs[i], NULL, 10);
}
return arr;
}
int **split_array(const int *s, int length) {
int **arrays = malloc(sizeof(int *) * 2);
int *arr_even = malloc(sizeof(int) * ((length + 2/ 2) - (length % 2)));
int *arr_odd = malloc(sizeof(int) * ((length + 2/ 2) + (length % 2)));
int even_count = 0;
int odd_count = 0;
for (int i = 0; i < length + 2; i++) {
if (i % 2 == 0) {
arr_even[even_count] = s[i];
even_count++;
} else {
arr_odd[odd_count] = s[i];
odd_count++;
}
}
arrays[0] = arr_even;
arrays[1] = arr_odd;
return arrays;
}
int main(int argc, char **argv) {
/* Replace the comments in the next two lines with the appropriate
arguments. Do not add any additional lines of code to the main
function or make other changes.
*/
int *full_array = build_array(argv, argc - 1);
int **result = split_array(full_array, sizeof(full_array));
printf("Original array:\n");
for (int i = 0; i < argc - 1; i++) {
printf("%d ", full_array[i]);
}
printf("\n");
printf("result[0]:\n");
for (int i = 0; i < argc / 2; i++) {
printf("%d ", result[0][i]);
}
printf("\n");
printf("result[1]:\n");
for (int i = 0; i < (argc - 1) / 2; i++) {
printf("%d ", result[1][i]);
}
printf("\n");
free(full_array);
free(result[0]);
free(result[1]);
free(result);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-01-27T00:41:56.699Z | Question from Code | v1 | how can i fix this code to ensure my memory is freed correctly | int *build_array(char **strs, int size) {
int *arr = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
arr[i] = strtol(strs[i], NULL, 10);
}
return arr;
}
int **split_array(const int *s, int length) {
int **arrays = malloc(sizeof(int *) * 2);
int *arr_even = malloc(sizeof(int) * ((length + 2/ 2) - (length % 2)));
int *arr_odd = malloc(sizeof(int) * ((length + 2/ 2) + (length % 2)));
int even_count = 0;
int odd_count = 0;
for (int i = 0; i < length + 2; i++) {
if (i % 2 == 0) {
arr_even[even_count] = s[i];
even_count++;
} else {
arr_odd[odd_count] = s[i];
odd_count++;
}
}
arrays[0] = arr_even;
arrays[1] = arr_odd;
return arrays;
}
int main(int argc, char **argv) {
/* Replace the comments in the next two lines with the appropriate
arguments. Do not add any additional lines of code to the main
function or make other changes.
*/
int *full_array = build_array(argv, argc - 1);
int **result = split_array(full_array, sizeof(full_array));
printf("Original array:\n");
for (int i = 0; i < argc - 1; i++) {
printf("%d ", full_array[i]);
}
printf("\n");
printf("result[0]:\n");
for (int i = 0; i < argc / 2; i++) {
printf("%d ", result[0][i]);
}
printf("\n");
printf("result[1]:\n");
for (int i = 0; i < (argc - 1) / 2; i++) {
printf("%d ", result[1][i]);
}
printf("\n");
free(full_array);
free(result[0]);
free(result[1]);
free(result);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-01-29T08:55:07.688Z | General Question | v1 | given a program where a pointer to an array of char pointers is passed as an argument, how can i print out the first 5 characters? | null | null | null |
63c6479f5f004bf4898cf545 | 2023-01-29T08:59:36.211Z | Question from Code | v1 | how can i index input to get the first character | int check_permissions(char *permission_field, char *required_permissions) {
for (int i = 0; i < 9; i++) {
if (required_permissions[i] == 'w' && permission_field[i] != 'w') {
return 1;
} else if (required_permissions[i] == 'r' && permission_field[i] != 'r') {
return 1;
} else if (required_permissions[i] == 'x' && permission_field[i] != 'x') {
return 1;
}
}
return 0;
}
int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
char ls_permissions[10];
int ls_size;
scanf("%*s %*d");
// TODO: Process command line arguments.
int size = strtol(argv[1], NULL, 10);
char *input;
char *permissions = malloc(sizeof(char *) * 9);
if (argc == 3) {
input = argv[2];
for (int i = 0; i < 9; i++) {
permissions[i] = input[i + 1];
printf("%sB \n", &input[2]);
}
}
int result = 0;
while (scanf("%s %*d %*s %*s %d %*s %*d %*s %*s", ls_permissions, &ls_size) != EOF) {
if (input[0] != 'd') {
if (argc == 2) {
if (ls_size >= size) {
result++;
}
} else if (argc == 3 && ls_size >= size && check_permissions(ls_permissions, permissions) == 0) {
result++;
}
}
}
//free(permissions);
printf("%d\n", result);
free(permissions);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-01-29T09:00:41.728Z | Question from Code | v1 | how can i make permissions equal to the last 9 characters of input | int check_permissions(char *permission_field, char *required_permissions) {
for (int i = 0; i < 9; i++) {
if (required_permissions[i] == 'w' && permission_field[i] != 'w') {
return 1;
} else if (required_permissions[i] == 'r' && permission_field[i] != 'r') {
return 1;
} else if (required_permissions[i] == 'x' && permission_field[i] != 'x') {
return 1;
}
}
return 0;
}
int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
char ls_permissions[10];
int ls_size;
scanf("%*s %*d");
// TODO: Process command line arguments.
int size = strtol(argv[1], NULL, 10);
char *input;
char *permissions = malloc(sizeof(char *) * 9);
if (argc == 3) {
input = argv[2];
for (int i = 0; i < 9; i++) {
permissions[i] = input[i + 1];
printf("%sB \n", &input[2]);
}
}
int result = 0;
while (scanf("%s %*d %*s %*s %d %*s %*d %*s %*s", ls_permissions, &ls_size) != EOF) {
if (input[0] != 'd') {
if (argc == 2) {
if (ls_size >= size) {
result++;
}
} else if (argc == 3 && ls_size >= size && check_permissions(ls_permissions, permissions) == 0) {
result++;
}
}
}
//free(permissions);
printf("%d\n", result);
free(permissions);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-01-29T09:07:32.636Z | General Question | v1 | why is it that when i index a pointer to a char array at index n, it gives me the same array starting from index n to the end? | null | null | null |
63c6479f5f004bf4898cf545 | 2023-02-02T22:52:09.649Z | Help Fix Code | v1 | null | int truncate(char *s, int n) {
char new_str[strlen(s)];
strncpy(new_str, s, n);
new_str[strlen(s) - 1] = '\0';
s = new_str;
return strlen(s) - n;
}
| Modify s so it becomes the first n characters of s, and return how many letters in s were removed | null |
63c6479f5f004bf4898cf545 | 2023-02-09T21:16:44.198Z | Help Write Code | v1 | null | null | null | First, allocate space for m `struct pixel *` values, where m is the
* height of the image. Each pointer will eventually point to one row of
* pixel data.
* 2. For each pointer you just allocated, initialize it to point to
* heap-allocated space for an entire row of pixel data.
* 3. Use the given file and pixel_array_offset to initialize the actual
* struct pixel values. Assume that `sizeof(struct pixel) == 3`, which is
* consistent with the bitmap file format.
* NOTE: We've tested this assumption on the Teaching Lab machines, but
* if you're trying to work on your own computer, we strongly recommend
* checking this assumption!
* 4. Return the address of the first `struct pixel *` you initialized. |
63c6479f5f004bf4898cf545 | 2023-02-09T21:22:10.042Z | Help Fix Code | v1 | null | struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) {
int arr = malloc(height * sizeof(struct pixel *));
for (int i = 0; i < height; i++) {
arr[i] = malloc(3 * width);
}
fseek(image, pixel_array_offset, SEEK_SET);
fread(arr, 3, 1, image);
return arr[0];
}
| First, allocate space for m `struct pixel *` values, where m is the
* height of the image. Each pointer will eventually point to one row of
* pixel data.
* 2. For each pointer you just allocated, initialize it to point to
* heap-allocated space for an entire row of pixel data.
* 3. Use the given file and pixel_array_offset to initialize the actual
* struct pixel values. Assume that `sizeof(struct pixel) == 3`, which is
* consistent with the bitmap file format.
* NOTE: We've tested this assumption on the Teaching Lab machines, but
* if you're trying to work on your own computer, we strongly recommend
* checking this assumption!
* 4. Return the address of the first `struct pixel *` you initialized. | null |
63c6479f5f004bf4898cf545 | 2023-02-09T21:30:35.718Z | Question from Code | v1 | how do i make this compile | struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) {
struct pixel arr = malloc(height * sizeof(struct pixel *));
for (int i = 0; i < height; i++) {
&arr[i] = malloc(3 * width);
}
fseek(image, pixel_array_offset, SEEK_SET);
fread(arr, 3, 1, image);
return arr[0];
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-09T21:36:01.210Z | Help Fix Code | v1 | null | struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) {
struct pixel **arr = malloc(height * sizeof(struct pixel *));
for (int i = 0; i < height; i++) {
arr[i] = malloc(3 * width);
}
fseek(image, pixel_array_offset, SEEK_SET);
fread(arr, 3, width, image);
return arr[0];
} | * Read in pixel array by following these instructions:
*
* 1. First, allocate space for m `struct pixel *` values, where m is the
* height of the image. Each pointer will eventually point to one row of
* pixel data.
* 2. For each pointer you just allocated, initialize it to point to
* heap-allocated space for an entire row of pixel data.
* 3. Use the given file and pixel_array_offset to initialize the actual
* struct pixel values. Assume that `sizeof(struct pixel) == 3`, which is
* consistent with the bitmap file format.
* NOTE: We've tested this assumption on the Teaching Lab machines, but
* if you're trying to work on your own computer, we strongly recommend
* checking this assumption!
* 4. Return the address of the first `struct pixel *` you initialized.
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-09T21:56:44.520Z | Help Fix Code | v1 | null | struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) {
struct pixel **arr = malloc(height * sizeof(struct pixel *));
for (int i = 0; i < height; i++) {
arr[i] = malloc(3 * width);
}
fseek(image, pixel_array_offset, SEEK_SET);
for (int i = 0; i < height; i++) {
fread(arr, 3, width, image);
}
return arr;
} | /*
* Read in pixel array by following these instructions:
*
* 1. First, allocate space for m `struct pixel *` values, where m is the
* height of the image. Each pointer will eventually point to one row of
* pixel data.
* 2. For each pointer you just allocated, initialize it to point to
* heap-allocated space for an entire row of pixel data.
* 3. Use the given file and pixel_array_offset to initialize the actual
* struct pixel values. Assume that `sizeof(struct pixel) == 3`, which is
* consistent with the bitmap file format.
* NOTE: We've tested this assumption on the Teaching Lab machines, but
* if you're trying to work on your own computer, we strongly recommend
* checking this assumption!
* 4. Return the address of the first `struct pixel *` you initialized.
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-09T21:59:10.119Z | Help Fix Code | v1 | null |
void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) {
fseek(image,10, SEEK_SET);
fread(&pixel_array_offset, sizeof(int), 1, image);
fseek(image, 18, SEEK_SET);
fread(&width, sizeof(int), 1, image);
fseek(image, 22, SEEK_SET);
fread(&height, sizeof(int), 1, image);
} | /*
* Read in the location of the pixel array, the image width, and the image
* height in the given bitmap file.
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-10T04:52:44.413Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
while (curr != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
}
User *new_user = malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
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 |
63c6479f5f004bf4898cf545 | 2023-02-10T04:54:55.268Z | 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) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
while (curr != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
curr = curr->next;
}
User *new_user = malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
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 |
63c6479f5f004bf4898cf545 | 2023-02-10T04:55:38.151Z | Question from Code | v1 | how do i add a user to the list | /*
* 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) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
while (curr != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
curr = curr->next;
}
User *new_user = malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
curr->next = new_user;
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-10T04:56:26.632Z | Question from Code | v1 | what line of code do i need to add to add new_user to the list | /*
* 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) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
while (curr != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
curr = curr->next;
}
User *new_user = malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
curr->next = new_user;
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-10T05:35:03.322Z | Question from Code | v1 | will this code add a user to the end of the linked list | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
User *new_user = malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
if (curr == NULL) {
curr = new_user;
}
while (curr->next != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
curr = curr->next;
}
curr->next = new_user;
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-10T05:37:08.184Z | Question from Code | v1 | will this code add a user to the end of the linked list | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
User *new_user = malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
if (curr == NULL) {
curr = new_user;
return 0;
}
while (curr->next != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
curr = curr->next;
}
curr->next = new_user;
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-10T20:46:34.188Z | Question from Code | v1 | why do i get a segmentation fault when i try to print the contents of the file? how can i fix it? | int print_user(const User *user) {
if (user == NULL) {
return 1;
}
FILE *file;
file = fopen(user->profile_pic, "r");
char line[10];
while (fgets(line, 10, file) != NULL) {
printf("%s", line);
}
fclose(file);
printf("Name: %s\n", (char *)user->name);
printf("------------------------------------------\n");
printf("Friends:\n");
int count = 0;
while ((char *)user->friends[count] != NULL) {
printf("%s\n", user->friends[count]->name);
count++;
}
printf("------------------------------------------\n");
printf("Posts:\n");
Post *curr = user->first_post;
while (curr != NULL) {
printf("From: %s\n", curr->author);
printf("Date: %s\n", ctime(curr->date));
printf("%s\n\n", curr->contents);
if (curr->next != NULL) {
printf("===\n\n");
}
curr = curr->next;
}
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-10T22:20:45.466Z | Question from Code | v1 | how can i fix my code so that i can assign new_post's date, which is of type time_t, to curr time? | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
int friend_mutuality = 0;
for(int i = 0; i < MAX_FRIENDS; i++) {
if (author->friends[i] == target) {
friend_mutuality++;
}
}
if (friend_mutuality == 0) {
return 1;
}
// Make a new post
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
time_t curr_time= sizeof(time_t);
time(&curr_time);
new_post->date = ctime(&curr_time);
if (target->first_post == NULL) {
new_post->next = NULL;
} else {
new_post->next = target->first_post;
target->first_post = new_post;
}
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-10T22:23:03.446Z | Question from Code | v1 | how can i fix this to get rid of the incompatible type error | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
int friend_mutuality = 0;
for(int i = 0; i < MAX_FRIENDS; i++) {
if (author->friends[i] == target) {
friend_mutuality++;
}
}
if (friend_mutuality == 0) {
return 1;
}
// Make a new post
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
time_t curr_time= sizeof(time_t);
time(&curr_time);
new_post->date = ctime(&curr_time);
if (target->first_post == NULL) {
new_post->next = NULL;
} else {
new_post->next = target->first_post;
target->first_post = new_post;
}
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-10T22:26:21.906Z | Help Fix Code | v1 | null | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
int friend_mutuality = 0;
for(int i = 0; i < MAX_FRIENDS; i++) {
if (author->friends[i] == target) {
friend_mutuality++;
}
}
if (friend_mutuality == 0) {
return 1;
}
// Make a new post
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
time_t curr_time= sizeof(time_t);
time(&curr_time);
new_post->date = ctime(&curr_time);
if (target->first_post == NULL) {
new_post->next = NULL;
} else {
new_post->next = target->first_post;
target->first_post = new_post;
}
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
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-10T22:27:52.059Z | Question from Code | v1 | will this compile and if not what i can i do to change it? new_post->date must be of type time_t | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
int friend_mutuality = 0;
for(int i = 0; i < MAX_FRIENDS; i++) {
if (author->friends[i] == target) {
friend_mutuality++;
}
}
if (friend_mutuality == 0) {
return 1;
}
// Make a new post
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
time_t curr_time= sizeof(time_t);
time(&curr_time);
new_post->date = ctime(&curr_time);
if (target->first_post == NULL) {
new_post->next = NULL;
} else {
new_post->next = target->first_post;
}
target->first_post = new_post;
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-10T22:34:26.932Z | Question from Code | v1 | how to fix this so it will compile? | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
int friend_mutuality = 0;
for(int i = 0; i < MAX_FRIENDS; i++) {
if (author->friends[i] == target) {
friend_mutuality++;
}
}
if (friend_mutuality == 0) {
return 1;
}
// Make a new post
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
time_t curr_time= sizeof(time_t);
time(&curr_time);
new_post->date = curr_time;
if (target->first_post == NULL) {
new_post->next = NULL;
} else {
new_post->next = target->first_post;
}
target->first_post = new_post;
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T15:06:30.327Z | Question from Code | v1 | how can i fix this so that it compiles | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
int friend_mutuality = 0;
for(int i = 0; i < MAX_FRIENDS; i++) {
if (author->friends[i] == target) {
friend_mutuality++;
}
}
if (friend_mutuality == 0) {
return 1;
}
// Make a new post
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
time_t curr_time= sizeof(time_t);
time(&curr_time);
new_post->date = curr_time;
if (target->first_post == NULL) {
new_post->next = NULL;
} else {
new_post->next = target->first_post;
}
target->first_post = new_post;
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T15:19:21.125Z | Question from Code | v1 | what can i change to get rid of the makes pointer from integer without a cast error | time_t curr_time = sizeof(time(NULL));
time(&curr_time);
new_post->date = curr_time; | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T15:21:17.586Z | Question from Code | v1 | what can i do to fix the makes pointer from integer without a cast error | time_t curr_time = time(NULL);
time(&curr_time);
new_post->date = curr_time; | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T21:06:37.717Z | Question from Code | v1 | what causes the segmentation fault | int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
*user_ptr_del = NULL;
free(curr);
} else {
return 1;
}
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
curr->next = curr->next->next;
}
return -1;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T21:08:57.187Z | Question from Code | v1 | how do i remove the segfault | int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
*user_ptr_del = NULL;
free(curr);
} else {
return 1;
}
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
curr->next = curr->next->next;
}
return -1;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T22:06:58.721Z | Help Fix Code | v1 | null | int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
*user_ptr_del = NULL;
free(curr);
return 0;
} else {
return 1;
}
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
curr->next = curr->next->next;
}
return 0;
} | /*
* From the list pointed to by *user_ptr_del, delete the user
* with the given name.
* Return:
* - 0 on success.
* - 1 if a user with this name does not exist.
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-11T22:09:19.549Z | Question from Code | v1 | will this cause a segmentation fault? how do i fix it? | int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
*user_ptr_del = NULL;
free(curr);
return 0;
} else {
return 1;
}
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
free(curr->next);
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
free(curr->next);
curr->next = curr->next->next;
}
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T22:10:39.209Z | Help Fix Code | v1 | null | int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
*user_ptr_del = NULL;
free(curr);
return 0;
} else {
return 1;
}
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
free(curr->next);
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
free(curr->next);
curr->next = curr->next->next;
}
return 0;
} | /* * From the list pointed to by *user_ptr_del, delete the user * with the given name. * Return: * - 0 on success. * - 1 if a user with this name does not exist. */ | null |
63c6479f5f004bf4898cf545 | 2023-02-11T22:15:57.363Z | Question from Code | v1 | how do i properly delete and free the memory of a user? How do i fix the segmentation fault? | int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = curr;
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = *user_ptr_del;
} else {
return 1;
}
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T22:17:09.923Z | Help Fix Code | v1 | null | int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = *user_ptr_del;
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = *user_ptr_del;
} else {
return 1;
}
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
return 0;
} | /*
* From the list pointed to by *user_ptr_del, delete the user
* with the given name.
*
* Return:
* - 0 on success.
* - 1 if a user with this name does not exist.
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-11T23:08:45.904Z | Question from Code | v1 | /*
* 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) {
// Check for error code 2
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
// Create a new user
User *new_user = malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
// If list is empty
if (*user_ptr_add == NULL) {
*user_ptr_add = new_user;
return 0;
}
while (curr->next != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
curr = curr->next;
}
curr->next = new_user;
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T23:09:22.955Z | Question from Code | v1 | /*
* 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)
*/
how do i fix this code? | int create_user(const char *name, User **user_ptr_add) {
// Check for error code 2
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
// Create a new user
User *new_user = malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
// If list is empty
if (*user_ptr_add == NULL) {
*user_ptr_add = new_user;
return 0;
}
while (curr->next != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
curr = curr->next;
}
curr->next = new_user;
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-11T23:09:56.728Z | Question from Code | v1 | how can i check if the name exists in the code already or not? | int create_user(const char *name, User **user_ptr_add) {
// Check for error code 2
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
// Create a new user
User *new_user = malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
// If list is empty
if (*user_ptr_add == NULL) {
*user_ptr_add = new_user;
return 0;
}
while (curr->next != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
curr = curr->next;
}
curr->next = new_user;
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T01:58:09.175Z | Help Fix Code | v1 | null | void remove_friend(const char *name, User *ptr_friend_user, int index) {
User *friend = ptr_friend_user;
for (int i = index; i < MAX_FRIENDS - 1; i++) {
friend->friends[i] = friend->friends[i + 1];
}
}
void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
remove_friend(name, curr, i);
}
}
while (curr->next != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
remove_friend(name, curr, i);
}
}
curr = curr->next;
}
}
| remove the deleted user from the friendlist | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:02:08.468Z | Help Fix Code | v1 | null | void remove_friend(const char *name, User *ptr_friend_user, int index) {
User *friend = ptr_friend_user;
for (int i = index; i < MAX_FRIENDS - 1; i++) {
friend->friends[i] = friend->friends[i + 1];
}
}
void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
remove_friend(name, curr, i);
}
}
curr = curr->next;
}
}
| remove the deleted user from the friendlist
| null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:05:42.996Z | Help Fix Code | v1 | null | void remove_friend(const char *name, User *ptr_friend_user, int index) {
User *friend = ptr_friend_user;
for (int i = index; i < MAX_FRIENDS - 1; i++) {
friend->friends[i] = friend->friends[i + 1];
}
friend->friends[MAX_FRIENDS - 1] = NULL;
}
void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
remove_friend(name, curr, i);
}
}
curr = curr->next;
}
}
| remove the deleted user from the friendlist | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:12:18.794Z | Question from Code | v1 | what can i do to fix this so that a user is removed from the friendslist of all users | void remove_friend(const char *name, User *ptr_friend_user, int index) {
User *friend = ptr_friend_user;
for (int i = index; i < MAX_FRIENDS - 1; i++) {
friend->friends[i] = friend->friends[i + 1];
}
friend->friends[MAX_FRIENDS - 1] = NULL;
}
void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
remove_friend(name, curr, i);
}
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:30:18.589Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
User *temp = malloc(sizeof(User));
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
temp = curr->friends[i];
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
free(temp);
}
} | delete user from all the friendlists of other users | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:33:28.503Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
User *temp = malloc(sizeof(User));
temp = curr->friends[i];
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
free(temp);
}
}
curr = curr->next;
}
} | delete user from all the friendlists of other users | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:33:53.757Z | Question from Code | v1 | how can i properly initialize temp | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
User *temp = malloc(sizeof(User));
temp = curr->friends[i];
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
free(temp);
}
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:38:36.908Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
}
} | delete the user in every friendlist | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:39:28.370Z | Question from Code | v1 | does this remove the friend from the friendlist of every user? and if not how can i fix it | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:46:51.876Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
printf("%s", curr->friends[i]->name);
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
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.
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:50:43.564Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
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 | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:52:47.218Z | Question from Code | v1 | what can i fix to make sure memory is allocated and deallocated properly? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:54:26.529Z | Question from Code | v1 | what can i do to fix this code | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T02:57:32.435Z | Question from Code | v1 | does remove_friends properly remove the user from the friendlist? what can i change? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T03:09:51.633Z | Question from Code | v1 | will this remove the deleted user from all user's friendlists? |
void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T03:10:51.487Z | Question from Code | v1 | will this remove the deleted user from all user's friendlists?
| int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T03:11:21.004Z | Question from Code | v1 | is this code correct | int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T03:12:02.453Z | Question from Code | v1 | is this correct | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T03:12:51.066Z | Question from Code | v1 | how can i fix this code | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T03:15:38.159Z | Question from Code | v1 | how can i make sure curr is initialized to *user_ptr_del in remove_friends | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T03:17:55.452Z | Question from Code | v1 | how do i prevent the segmentation faults | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T04:13:36.631Z | Question from Code | v1 | is an array of users the same as a linked list of users? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp(curr->friends[i]->name, name) == 0) {
for (int j = i; i < MAX_FRIENDS - 1; j ++) {
curr->friends[j] = curr->friends[j + 1];
}
curr->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
return 0;
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T04:43:54.343Z | Question from Code | v1 | will this code remove the user from every friendlist? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T04:45:21.374Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
if (*user_ptr_del == NULL) {
return 1;
}
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
free(temp);
remove_friends(name, user_ptr_del);
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.
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-12T04:48:31.549Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
// Check for User Non-existence
// Create users friend1 and friend2
User *friend1 = find_user(name1, head);
User *friend2 = find_user(name2, head);
if (friend1 == NULL || friend2 == NULL) {
return 4;
}
// Check for same user passed twice
if (friend1 == friend2) {
return 3;
}
// Check for full friends list
if (friend1->friends[MAX_FRIENDS - 1]->name != NULL || friend2->friends[MAX_FRIENDS - 1]->name != NULL) {
return 2;
}
// Check for friend already exists
for (int i = 0; i < MAX_FRIENDS; i++) {
if (friend1->friends[i] == friend2 || friend2->friends[i] == friend1) {
return 1;
}
}
int f1_added = 0;
int f2_added = 0;
int count = 0;
while (f1_added == 0 || f2_added == 0) {
if (friend1->friends[count] == NULL && f1_added == 0) {
friend1->friends[count] = friend2;
f1_added = 1;
}
if (friend2->friends[count] == NULL && f2_added == 0) {
friend2->friends[count] = friend1;
f2_added = 1;
}
count++;
}
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.
*
* 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. | null |
63c6479f5f004bf4898cf545 | 2023-02-12T04:53:24.277Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
if (*user_ptr_del == NULL) {
return 1;
}
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
remove_friends(name, user_ptr_del);
free(temp);
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.
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-12T04:56:45.975Z | Question from Code | v1 | should temp be allocated size user or user * | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
if (*user_ptr_del == NULL) {
return 1;
}
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
remove_friends(name, user_ptr_del);
free(temp);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T05:02:51.374Z | Question from Code | v1 | what can i change so this code properly deletes a user from the friendslists | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
if (*user_ptr_del == NULL) {
return 1;
}
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
remove_friends(name, user_ptr_del);
free(temp);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T05:03:25.420Z | Question from Code | v1 | how can i fix the code | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
if (*user_ptr_del == NULL) {
return 1;
}
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
remove_friends(name, user_ptr_del);
free(temp);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T05:06:29.686Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
if (*user_ptr_del == NULL) {
return 1;
}
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
free(temp);
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
remove_friends(name, user_ptr_del);
free(temp);
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.
*/ | null |
63c6479f5f004bf4898cf545 | 2023-02-12T05:07:30.956Z | Question from Code | v1 | will this code behave as intended?
Here is what it should do:
* 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.
*/ | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
}
int delete_user(const char *name, User **user_ptr_del) {
// Delete user from list
User *curr = *user_ptr_del;
User *temp = malloc(sizeof(User));
if (*user_ptr_del == NULL) {
return 1;
}
// If 1 element in the list
if (curr->next == NULL) {
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = NULL;
free(temp);
return 0;
} else {
return 1;
}
}
// If 1st element is removed
if (strcmp(curr->name, name) == 0) {
temp = curr;
*user_ptr_del = curr->next;
free(temp);
return 0;
}
while (strcmp(curr->next->name, name) != 0 && curr->next != NULL) {
curr = curr->next;
}
// If name does not exist
if (curr->next == NULL) {
free(temp);
return 1;
}
// If user to be removed is the last one
if (curr->next->next == NULL) {
temp = curr->next;
curr->next = NULL;
} else {
// If user to be removed is in the middle of the list
temp = curr->next;
curr->next = curr->next->next;
}
remove_friends(name, user_ptr_del);
free(temp);
return 0;
}
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T17:36:21.776Z | Question from Code | v1 | does this code properly remove a user by the name of variable name from all the friendlists of the linked list of users starting at ptr_users?
if not, how can fix it? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T17:37:40.184Z | Question from Code | v1 | does this properly shit all the friends after user in the list by one? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T17:41:46.027Z | Question from Code | v1 | does this code properly remove a friend from friendlists of all the users by shifting the list to the left by one after in the list after the user we want to remove? if not how can i fix it | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T17:51:26.945Z | Question from Code | v1 | do lines 4-14 properly assign variable u_count to the position of the user by the name name in the friends list, and f_count to the number of friends in the friendslist?
do lines 16-19 then properly remove the user from the friendlist of the users? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T17:53:45.572Z | Question from Code | v1 | how do i properly assign u_count to the index of the removed user in the friendslist? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T17:54:20.572Z | Question from Code | v1 | do lines 4-14 properly assign variable u_count to the position of the user by the name name in the friends list, and f_count to the number of friends in the friendslist?
if not, what can i change? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T17:55:23.927Z | Question from Code | v1 | do lines 16-19 then properly remove the user from the friendlist of the users? if not what can i change | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
for (int x = u_count; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T18:41:46.799Z | Question from Code | v1 | do i need to delete the memory of the removed user in friendslist? and if so how? | void remove_friends(const char *name, User **ptr_users) {
printf("bye");
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
printf("%s", curr->friends[0]->name);
if (f_count == 1 && u_count == 1) {
curr->friends[0] = NULL;
}
else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T18:42:47.700Z | Question from Code | v1 | Does this code properly remove friends from the friendlist? what do i need to change or add? | void remove_friends(const char *name, User **ptr_users) {
printf("bye");
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
printf("%s", curr->friends[0]->name);
if (f_count == 1 && u_count == 1) {
curr->friends[0] = NULL;
}
else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T18:44:06.096Z | Question from Code | v1 | how can i fix this so i remove the user from the friendlists? | void remove_friends(const char *name, User **ptr_users) {
printf("bye");
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
printf("%s", curr->friends[0]->name);
if (f_count == 1 && u_count == 1) {
curr->friends[0] = NULL;
}
else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T18:57:25.161Z | Question from Code | v1 | how do i delete the user from the friendslist if there is only one friend in the friendslist? | void remove_friends(const char *name, User **ptr_users) {
printf("bye");
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
printf("%s", curr->friends[0]->name);
if (f_count == 1 && u_count == 1) {
curr->friends[0] = NULL;
}
else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
}
curr->friends[f_count - 1] = NULL;
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:00:53.828Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
curr = curr->next;
}
} | remove the user from all the friendlists of the list of users | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:02:34.276Z | Question from Code | v1 | will this properly remove the user from a 1 element long friendlist of a user? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:03:03.114Z | Question from Code | v1 | is this code correct? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:03:22.291Z | Question from Code | v1 | what do i need to do to fix this | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:05:00.263Z | Question from Code | v1 | will this code correctly remove a user from all friendlists? if not, how can i fix it | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:12:54.684Z | Help Fix Code | v1 | null | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;Avoid remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
if (f_count == 1 && u_count == 1) {
User *blank = malloc(sizeof(User) * MAX_FRIENDS);
curr->friends = blank;
} else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
}
curr = curr->next;
}
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
curr = curr->next;
}
} | remove user from all friendslists | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:13:40.085Z | Question from Code | v1 | how do i fix it to make this compile | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;Avoid remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
if (f_count == 1 && u_count == 1) {
User *blank = malloc(sizeof(User) * MAX_FRIENDS);
curr->friends = blank;
} else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
}
curr = curr->next;
}
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:14:50.436Z | Question from Code | v1 | how do i fix the assignment to expression with array type error | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;Avoid remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
if (f_count == 1 && u_count == 1) {
User *blank = malloc(sizeof(User) * MAX_FRIENDS);
curr->friends = blank;
} else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
}
curr = curr->next;
}
}
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:16:33.765Z | Question from Code | v1 | is this correct | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
if (f_count == 1) {
curr->friends[0] = NULL;
} else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:22:37.451Z | Question from Code | v1 | will this code properly remove the user from a friendlist of length 1? if not, why? | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
if (f_count == 1) {
curr->friends[0] = NULL;
} else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:23:52.118Z | Question from Code | v1 | how do i remove a user from a friendlist of lenght 1 | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
if (f_count == 1) {
curr->friends[0] = NULL;
} else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T20:27:57.419Z | Question from Code | v1 | will this code properly remove the user from a friendlist of length 1? if not, what can i do to fix it | void remove_friends(const char *name, User **ptr_users) {
User *curr = *ptr_users;
while (curr != NULL) {
int f_count = 0;
int u_count = 0;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (curr->friends[i] != NULL) {
f_count++;
if (strcmp(curr->friends[i]->name, name) == 0) {
u_count = f_count;
}
}
}
if (u_count != 0) {
if (f_count == 1) {
curr->friends[0] = NULL;
} else {
for (int x = u_count - 1; x < f_count - 1; x++) {
curr->friends[x] = curr->friends[x + 1];
}
curr->friends[f_count - 1] = NULL;
}
}
curr = curr->next;
}
} | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T21:38:50.418Z | General Question | v1 | how do i initialize time_t properly so i can get the current time | null | null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T22:12:30.627Z | Question from Code | v1 | will this properly set curr_time to the current time without junk bites? how can i fix it | time_t curr_time = sizeof(time_t);
time(&curr_time);
new_post->date = &curr_time;
| null | null |
63c6479f5f004bf4898cf545 | 2023-02-12T22:13:58.742Z | Question from Code | v1 | why do i keep getting the wrong date with this | time_t curr_time;
time(&curr_time);
new_post->date = &curr_time;
| null | null |