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
⌀ |
---|---|---|---|---|---|---|---|
63c648b75f004bf4898cff04 | 2023-01-26T23:54:00.183Z | General Question | v1 | dynamically assign array on size of 5 ints at a given pointer | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-26T23:54:56.650Z | General Question | v1 | Fibonacci function in c | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-26T23:55:27.810Z | General Question | v1 | how to write Fibonacci function in c | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T00:51:13.467Z | Explain Code | v1 | null | int *build_array(char **strs, int size) {
int *array = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
array[i] = strtol(strs[i], NULL, 10);
}
return array;
} | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T00:53:03.999Z | Help Fix Code | v1 | null | int *build_array(char **strs, int size) {
int *array = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
array[i] = strtol(strs[i], NULL, 10);
}
return array;
} | convert strings in strs to ints in an array and return that array | null |
63c648b75f004bf4898cff04 | 2023-01-27T01:20:41.002Z | Explain Code | v1 | null | int **split_array(const int *s, int length) {
int num_odds = 0;
int num_evens = 0;
for (int i = 0; i < length; i++) {
if ((i % 2) == 0) {
num_evens += 1;
}
else {
num_odds += 1;
}
}
int *final_array = malloc(2 * sizeof(char*));
final_array[0] = malloc(num_evens * sizeof(int));
final_array[1] = malloc(num_odds * sizeof(int));
int even_counter = 0;
int odd_counter = 0;
for (int i = 0; i < length; i++) {
if ((i % 2) == 0) {
final_array[0][even_counter] = s[i];
even_counter += 1;
}
else {
final_array[1][odd_counter] = s[i];
odd_counter += 1;
}
}
return final_array;
} | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T01:50:45.816Z | General Question | v1 | how to create 9 element character array? | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T01:51:30.336Z | General Question | v1 | what is char*? | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T01:52:09.303Z | General Question | v1 | char* as input to a function, then later use it for an array of characters? | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T01:54:13.118Z | General Question | v1 | represent strings of length 9 with char* | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T01:57:19.426Z | Explain Code | v1 | null | int check_permissions(char *given, char *required){
for (i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
return 1;
}
return 0;
}
} | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T02:13:29.672Z | General Question | v1 | how to read a file line by line in c | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T02:38:21.682Z | General Question | v1 | scan line using scanf | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T02:51:48.097Z | General Question | v1 | scan the whole input line using scanf | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T02:58:54.183Z | General Question | v1 | initialize a string to hold the scanned line using scanf | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T03:16:21.199Z | General Question | v1 | using scanf to split between whitespace | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:30:08.300Z | General Question | v1 | initialize a 9 character string called permissions | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:31:44.933Z | General Question | v1 | use scanf to take input and save it in a string of length 9 represented by the name permissions | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:41:03.281Z | General Question | v1 | can you answer questions related to linux as well? | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:47:09.699Z | Question from Code | v1 | running this returns in a stack smashing detected and the program terminates, how to fix it? | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char permissions[10];
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
return 0; | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:48:17.855Z | Question from Code | v1 | how can I make `permissions` a pointer and use it to avoid the stack smashing error? | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char permissions[10];
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
return 0; | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:50:35.564Z | Question from Code | v1 | changing char permissions[10] to char *permissions = malloc(10) still results in a stack smashing error | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char permissions[10];
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
return 0; | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:52:04.608Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char *permissions = malloc(10 * sizeof(char));
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
return 0; | running this results in stack smashing error, how to fix? | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:53:59.026Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char *permissions = malloc(10 * sizeof(char));
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
free(permissions);
return 0;
}
| running this results in stack smashing error, how to fix? | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:55:47.631Z | Question from Code | v1 | running this results in stack smashing error, how to fix? | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char *permissions = malloc(10 * sizeof(char));
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
free(permissions);
return 0;
}
| null | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:56:45.373Z | Question from Code | v1 | running this results in stack smashing error, how to fix? | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char *permissions = malloc(10 * sizeof(char));
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
free(permissions);
return 0;
}
| null | null |
63c648b75f004bf4898cff04 | 2023-01-27T05:57:30.475Z | Question from Code | v1 | how should permissions be changed to avoid a stack smashing error | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char *permissions = malloc(10 * sizeof(char));
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
free(permissions);
return 0;
}
| null | null |
63c648b75f004bf4898cff04 | 2023-01-27T06:20:27.528Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char *permissions = malloc(10 * sizeof(char));
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
free(permissions);
return 0;
}
| encountering a stack smashing error, how to fix the code? | null |
63c648b75f004bf4898cff04 | 2023-01-27T06:21:49.996Z | Question from Code | v1 | getting a stack smashing error, how to fix? | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char *permissions = malloc(10 * sizeof(char));
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
free(permissions);
return 0;
}
| null | null |
63c648b75f004bf4898cff04 | 2023-01-27T06:22:36.124Z | Question from Code | v1 | how to allocate 10 characters for permissions? | #include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
for (int i = 0; i < 9; i++) {
if (required[i] != '-' && given[i] == '-') {
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;
}
int req_size = strtol(argv[1], NULL, 10);
char *permissions = malloc(10 * sizeof(char));
int file_size;
int counter = 0;
scanf("%*[^\n]");
while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {
if (permissions[0] != 'd') {
if (argc == 3 && file_size >= req_size) {
char *required = argv[2];
if (check_permissions(permissions, required) == 0) {
counter += 1;
}
}
else if (file_size >= req_size) {
counter += 1;
}
}
}
printf("%i \n", counter);
// TODO: Process command line arguments.
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
free(permissions);
return 0;
}
| null | null |
63c648b75f004bf4898cff04 | 2023-01-27T19:14:33.829Z | Explain Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
/* Return a pointer to an array of two dynamically allocated arrays of ints.
The first array contains the elements of the input array s that are
at even indices. The second array contains the elements of the input
array s that are at odd indices.
Do not allocate any more memory than necessary. You are not permitted
to include math.h. You can do the math with modulo arithmetic and integer
division.
*/
int **split_array(const int *s, int length) {
int num_odds = 0;
int num_evens = 0;
for (int i = 0; i < length; i++) {
if ((i % 2) == 0) {
num_evens += 1;
}
else {
num_odds += 1;
}
}
int *final_array = malloc(2 * sizeof(char*));
final_array[0] = malloc(num_evens * sizeof(int));
final_array[1] = malloc(num_odds * sizeof(int));
int even_counter = 0;
int odd_counter = 0;
for (int i = 0; i < length; i++) {
if ((i % 2) == 0) {
final_array[0][even_counter] = s[i];
even_counter += 1;
}
else {
final_array[1][odd_counter] = s[i];
odd_counter += 1;
}
}
return final_array;
}
/* Return a pointer to an array of ints with size elements.
- strs is an array of strings where each element is the string
representation of an integer.
- size is the size of the array
*/
int *build_array(char **strs, int size) {
int *array = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++) {
array[i] = strtol(strs[i], NULL, 10);
}
return array;
}
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, argc-1);
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 |
63c648b75f004bf4898cff04 | 2023-01-27T19:24:43.113Z | General Question | v1 | how to split string? | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T19:26:15.219Z | General Question | v1 | slice a string from an index | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-27T19:28:50.867Z | General Question | v1 | slice a string from an index without using strncpy | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-30T04:20:25.275Z | Question from Code | v1 | getting segmentation fault, how to fix? | char* season = "winter";
char* holiday = malloc(20 * sizeof(char));
strncpy(holiday, "Valentine's Day", 16);
season[17] = '\0'; | null | null |
63c648b75f004bf4898cff04 | 2023-01-30T04:21:34.327Z | Question from Code | v1 | getting segmentation fault, how to fix? | char* holiday = malloc(20 * sizeof(char));
strncpy(holiday, "Valentine's Day", 16);
season[17] = '\0'; | null | null |
63c648b75f004bf4898cff04 | 2023-01-30T04:23:37.359Z | General Question | v1 | Define a stack-allocated string called holiday that has space for 20 characters
including the null terminator. Set its initial value to "Valentine's Day". | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T00:06:54.625Z | General Question | v1 | check if two strings are equal in c | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T00:12:33.658Z | General Question | v1 | length of string | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T00:22:54.270Z | General Question | v1 | printf format for long unsigned int | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T00:46:41.429Z | General Question | v1 | append string to another string | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T00:48:05.840Z | General Question | v1 | using strncat to append a string to another string | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T00:53:24.719Z | General Question | v1 | what does strncpy return | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T01:03:52.040Z | General Question | v1 | append a space to a string | null | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T01:27:53.789Z | Question from Code | v1 | how to add a space in the string greeting | int main(int argc, char **argv) {
if (argc != 3) {
fprintf(stderr, "Usage: greeting message name\n");
return 1;
}
char greeting[20];
char *name = argv[2];
// Your code goes here
int length = strlen(argv[1]);
strncpy(greeting, argv[1], length);
strcat(greeting, " ");
strncat(greeting, name, 20 - strlen(greeting));
printf("%s\n", greeting);
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T01:28:17.568Z | Question from Code | v1 | how to use strcat to add a space to the end of greeting | int main(int argc, char **argv) {
if (argc != 3) {
fprintf(stderr, "Usage: greeting message name\n");
return 1;
}
char greeting[20];
char *name = argv[2];
// Your code goes here
int length = strlen(argv[1]);
strncpy(greeting, argv[1], length);
strcat(greeting, " ");
strncat(greeting, name, 20 - strlen(greeting));
printf("%s\n", greeting);
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-01-31T01:30:22.214Z | Help Fix Code | v1 | null | int main(int argc, char **argv) {
if (argc != 3) {
fprintf(stderr, "Usage: greeting message name\n");
return 1;
}
char greeting[20];
char *name = argv[2];
// Your code goes here
int length = strlen(argv[1]);
strncpy(greeting, argv[1], length);
strcat(greeting, " ");
strncat(greeting, name, 20 - strlen(greeting));
printf("%s\n", greeting);
return 0;
} | correct string not returning | null |
63c648b75f004bf4898cff04 | 2023-01-31T01:38:18.730Z | Help Fix Code | v1 | null | char greeting[20];
char *name = argv[2];
// Your code goes here
int length = strlen(argv[1]);
strncpy(greeting, argv[1], length);
strcat(greeting, " ");
strncat(greeting, name, 20 - strlen(greeting)); | append space to greeting string and then append name string to it | null |
63c648b75f004bf4898cff04 | 2023-02-03T23:07:26.691Z | General Question | v1 | sys.stdout() printing a newline character at the end of the file python | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T04:44:45.740Z | General Question | v1 | how to write a is to x as x is to b in today's mathematical terms | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T06:14:29.980Z | General Question | v1 | initialize an array in a struct with all null values | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T06:29:01.506Z | Question from Code | v1 | this leads to a segmentation fault, how to fix? | int create_user(const char *name, User **user_ptr_add) {
User *curr_user = *user_ptr_add;
if (strlen(name) > 29) {
return 2;
}
while (curr_user->next != NULL) {
if (strcmp(name, curr_user->name) == 0) {
return 1;
}
curr_user = curr_user->next;
}
struct user new_user;
strncpy(new_user.name, name, strlen(name));
new_user.name[strlen(name)] = '\0';
new_user.profile_pic[0] = '\0';
new_user.first_post = NULL;
memset(new_user.friends, '\0', sizeof(new_user.friends));
new_user.next = NULL;
return 0; | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T06:34:34.616Z | Question from Code | v1 | gives an error, how to fix? | int create_user(const char *name, User **user_ptr_add) {
User *curr_user = *user_ptr_add;
if (strlen(name) > 29) {
return 2;
}
while (curr_user->next != NULL) {
if (strcmp(name, curr_user->name) == 0) {
return 1;
}
curr_user = curr_user->next;
}
User *new_user = malloc(sizeof(User));
strncpy(new_user.name, name, strlen(name));
new_user.name[strlen(name)] = '\0';
new_user.profile_pic[0] = '\0';
new_user.first_post = NULL;
memset(new_user.friends, '\0', sizeof(new_user.friends));
new_user.next = NULL;
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T06:36:44.358Z | Question from Code | v1 | gives a segmentation fault, how to fix? | int create_user(const char *name, User **user_ptr_add) {
User *curr_user = *user_ptr_add;
if (strlen(name) > 29) {
return 2;
}
while (curr_user->next != NULL) {
if (strcmp(name, curr_user->name) == 0) {
return 1;
}
curr_user = curr_user->next;
}
User *new_user = malloc(sizeof(User));
strncpy(new_user->name, name, strlen(name));
new_user->name[strlen(name)] = '\0';
new_user->profile_pic[0] = '\0';
new_user->first_post = NULL;
memset(new_user->friends, '\0', sizeof(new_user->friends));
new_user->next = NULL;
*user_ptr_add = new_user;
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T06:37:19.796Z | Question from Code | v1 | how can I use `curr_user` ? | int create_user(const char *name, User **user_ptr_add) {
User *curr_user = *user_ptr_add;
if (strlen(name) > 29) {
return 2;
}
while (curr_user->next != NULL) {
if (strcmp(name, curr_user->name) == 0) {
return 1;
}
curr_user = curr_user->next;
}
User *new_user = malloc(sizeof(User));
strncpy(new_user->name, name, strlen(name));
new_user->name[strlen(name)] = '\0';
new_user->profile_pic[0] = '\0';
new_user->first_post = NULL;
memset(new_user->friends, '\0', sizeof(new_user->friends));
new_user->next = NULL;
*user_ptr_add = new_user;
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T06:38:53.319Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *curr_user = *user_ptr_add;
if (strlen(name) > 29) {
return 2;
}
while (curr_user->next != NULL) {
if (strcmp(name, curr_user->name) == 0) {
return 1;
}
curr_user = curr_user->next;
}
User *new_user = malloc(sizeof(User));
strncpy(new_user->name, name, strlen(name));
new_user->name[strlen(name)] = '\0';
new_user->profile_pic[0] = '\0';
new_user->first_post = NULL;
memset(new_user->friends, '\0', sizeof(new_user->friends));
new_user->next = NULL;
*user_ptr_add = new_user;
return 0;
} | create a new user with the given name and add it to the tail of the list pointed to by user_ptr_add | null |
63c648b75f004bf4898cff04 | 2023-02-06T07:16:30.197Z | Question from Code | v1 | gives segmentation fault, how to fix? | int create_user(const char *name, User **user_ptr_add) {
User *curr_user = *user_ptr_add;
if (strlen(name) > 29) {
return 2;
}
while (curr_user->next != NULL) {
if (strcmp(name, curr_user->name) == 0) {
return 1;
}
curr_user = curr_user->next;
}
User *new_user = malloc(sizeof(User));
strncpy(new_user->name, name, strlen(name));
new_user->name[strlen(name)] = '\0';
new_user->profile_pic[0] = '\0';
new_user->first_post = NULL;
memset(new_user->friends, '\0', sizeof(new_user->friends));
new_user->next = NULL;
curr_user->next = new_user;
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T07:22:34.513Z | Question from Code | v1 | not returning 1 even in the case a user with the name already exists, how to fix? | while (curr_user->next != NULL) {
if (strcmp(name, curr_user->name) == 0) {
return 1;
}
curr_user = curr_user->next;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T07:23:23.972Z | Explain Code | v1 | null | while (curr_user->next != NULL) {
if (strcmp(name, curr_user->name) == 0) {
return 1;
}
curr_user = curr_user->next;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-06T07:30:00.597Z | Explain Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *curr_user = *user_ptr_add;
if (strlen(name) > 29) {
return 2;
}
if (curr_user != NULL) {
while (curr_user->next != NULL) {
if (strcmp(name, curr_user->name) == 0) {
return 1;
}
curr_user = curr_user->next;
}
}
User *new_user = malloc(sizeof(User));
strncpy(new_user->name, name, strlen(name));
new_user->name[strlen(name)] = '\0';
new_user->profile_pic[0] = '\0';
new_user->first_post = NULL;
memset(new_user->friends, '\0', sizeof(new_user->friends));
new_user->next = NULL;
if (curr_user != NULL) {
curr_user->next = new_user;
}
else {
curr_user = new_user;
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-07T23:31:20.470Z | General Question | v1 | when inserting a new node into a linked list, how to check if the node with a value currently exists? | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-07T23:45:02.956Z | General Question | v1 | what is a pointer to pointer to structure in c | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-08T00:59:43.251Z | General Question | v1 | how to cast an object in c | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-08T01:21:23.130Z | General Question | v1 | check if a file is not openable in c using fopen | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-08T01:58:03.729Z | General Question | v1 | add a new element at the first empty spot in c | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-08T02:24:38.685Z | General Question | v1 | read lines from a file and output it in the console c | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-08T02:27:51.524Z | General Question | v1 | fgets example usage | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-08T02:31:28.481Z | General Question | v1 | example of fgets using fopen | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-08T04:18:07.372Z | Help Fix Code | v1 | null | for (int i; i < 10; i++){
printf("Name is: %i\n", i);
} | print name is 1, 2, 3, 4 and so on | null |
63c648b75f004bf4898cff04 | 2023-02-08T06:49:49.303Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
if (user1 == NULL || user2 == NULL) {
return 4;
}
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | function randomly returning segmentation fault | null |
63c648b75f004bf4898cff04 | 2023-02-08T07:21:28.830Z | General Question | v1 | how to bugfix a segmentation fault? | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-08T07:29:56.241Z | General Question | v1 | print time_t pointer in a readable format | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-08T07:30:48.863Z | General Question | v1 | get current time into a variable | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:12:32.023Z | Question from Code | v1 | getting a segmentation fault, how to fix? | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:13:25.535Z | Question from Code | v1 | how to dereference user2 to get a User* | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:13:47.186Z | Question from Code | v1 | getting a segmentation fault, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:15:14.792Z | Question from Code | v1 | getting a segmentation fault, how to fix? | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:27:42.273Z | Question from Code | v1 | getting a segmentation fault, how to fix? | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:28:13.979Z | Question from Code | v1 | getting a segmentation fault, how to fix? | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:29:13.479Z | Question from Code | v1 | getting a segmentation fault, how to fix? please tell the exact lines or chunks of code that might be causing the issue | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:34:50.560Z | Question from Code | v1 | getting segmentation fault, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:35:28.684Z | Question from Code | v1 | getting segmentation fault, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i])->name != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i])->name == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i])->name == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:46:49.451Z | Question from Code | v1 | getting a segmentation fault on specific inputs, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
printf("The head rn is: %s\n", head->name);
User *user1 = find_user(name1, head);
printf("The head after first search is: %s\n", head->name);
User *user2 = find_user(name2, head);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:47:47.668Z | Question from Code | v1 | how to make a copy of the head pointer | int make_friends(const char *name1, const char *name2, User *head) {
printf("The head rn is: %s\n", head->name);
User *user1 = find_user(name1, head);
printf("The head after first search is: %s\n", head->name);
User *user2 = find_user(name2, head);
if (user1 == NULL || user2 == NULL) {
printf("One or both users are NULL");
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:50:45.666Z | Question from Code | v1 | getting a segmentation fault on specific inputs, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:52:27.631Z | Question from Code | v1 | getting a segmentation fault on specific inputs, how to fix it without changing find_user? | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:53:46.074Z | Question from Code | v1 | getting a segmentation fault on specific inputs, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:54:44.148Z | Question from Code | v1 | getting a segmentation fault on specific inputs, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T04:55:31.433Z | Question from Code | v1 | getting a segmentation fault on specific inputs, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T05:02:06.031Z | Question from Code | v1 | getting a segmentation fault on specific inputs, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T05:02:51.427Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_one_friends++;
}
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
user_two_friends++;
}
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | getting a segmentation fault on specific inputs, how to fix it? | null |
63c648b75f004bf4898cff04 | 2023-02-09T05:05:06.073Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_one_friends++;
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_two_friends++;
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | add friends as required but getting a segmentation fault on specific inputs, how to fix it? | null |
63c648b75f004bf4898cff04 | 2023-02-09T05:06:10.617Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_one_friends++;
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_two_friends++;
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | getting a segmentation fault on specific inputs, how to fix it? | null |
63c648b75f004bf4898cff04 | 2023-02-09T05:07:35.666Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_one_friends++;
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_two_friends++;
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | getting a segmentation fault on specific inputs, how to fix it? | null |
63c648b75f004bf4898cff04 | 2023-02-09T05:33:50.436Z | Question from Code | v1 | getting a segmentation fault on specific inputs, how to fix it? | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_one_friends++;
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_two_friends++;
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-09T05:50:02.650Z | Question from Code | v1 | how to make two separate copies of head pointer | int make_friends(const char *name1, const char *name2, User *head) {
User *head_copy1 = head;
User *head_copy2 = head;
User *user1 = find_user(name1, head_copy1);
User *user2 = find_user(name2, head_copy2);
if (user1 == NULL || user2 == NULL) {
return 4;
}
printf("The first user is %s", user1->name);
printf("The second user is %s", user2->name);
if (strcmp(name1, name2) == 0) {
return 3;
}
int user_one_friends = 0;
int user_two_friends = 0;
int already_friends = 0;
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_one_friends++;
}
if ((user2->friends[i]) != NULL) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
already_friends += 1;
}
user_two_friends++;
}
}
if (already_friends == 2) {
return 1;
}
if (user_one_friends == MAX_FRIENDS || user_two_friends == MAX_FRIENDS) {
return 2;
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user1->friends[i]) == NULL) {
user1->friends[i] = user2;
break;
}
}
for (int i = 0; i < MAX_FRIENDS - 1; i++){
if ((user2->friends[i]) == NULL) {
user2->friends[i] = user1;
break;
}
}
return 0;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-10T06:51:29.211Z | General Question | v1 | how to get the current time in a malloc using ctime and time_t | null | null | null |
63c648b75f004bf4898cff04 | 2023-02-14T04:02:41.062Z | Question from Code | v1 | returns segmentation fault for very large values of capacity | char *copy(char *dest, const char *src, int capacity) {
for (int i = 0; i < capacity; i++) {
dest[i] = src[i];
}
dest[capacity] = '\0';
return dest;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-14T04:03:00.344Z | Question from Code | v1 | returns segmentation fault for very large values of capacity, how to fix? | char *copy(char *dest, const char *src, int capacity) {
for (int i = 0; i < capacity; i++) {
dest[i] = src[i];
}
dest[capacity] = '\0';
return dest;
} | null | null |
63c648b75f004bf4898cff04 | 2023-02-24T22:56:09.102Z | General Question | v1 | what does the total in ls -lF return mean? | null | null | null |