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 ⌀ |
|---|---|---|---|---|---|---|---|
63c647635f004bf4898cf351 | 2023-01-18T04:30:17.303Z | Question from Code | v1 | assign the amount in rain_today to the space rainfall points to | int main(int argc, char **argv) {
float *rainfall;
float rain_today;
} | null | null |
63c647635f004bf4898cf351 | 2023-02-07T21:51:18.185Z | Question from Code | v1 | Why am I getting segmentation fault | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
User *curr = *user_ptr_add;
while (curr->next != NULL) {
if (strcmp(name, curr->name) == 0) {
return 1;
}
... | null | null |
63c647635f004bf4898cf351 | 2023-02-07T22:17:08.664Z | Question from Code | v1 | strcmp is not working | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
// make new user
User *new_user = malloc(sizeof(User));
strncpy(new_user->name, name, sizeof(MAX_NAME - 1));
(new_user->name)[MAX_NAME - 1] = '\0';
... | null | null |
63c647635f004bf4898cf351 | 2023-02-07T22:17:57.317Z | Question from Code | v1 | is curr->name a string | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
// make new user
User *new_user = malloc(sizeof(User));
strncpy(new_user->name, name, sizeof(MAX_NAME - 1));
(new_user->name)[MAX_NAME - 1] = '\0';
... | null | null |
63c647635f004bf4898cf351 | 2023-02-07T22:18:59.859Z | Question from Code | v1 | how do I know whether name and curr->name are the same | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
// make new user
User *new_user = malloc(sizeof(User));
strncpy(new_user->name, name, sizeof(MAX_NAME - 1));
(new_user->name)[MAX_NAME - 1] = '\0';
... | null | null |
63c647635f004bf4898cf351 | 2023-02-07T22:22:40.387Z | Question from Code | v1 | what does strcmp(name, curr->name) do | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME) {
return 2;
}
// make new user
User *new_user = malloc(sizeof(User));
strncpy(new_user->name, name, sizeof(MAX_NAME - 1));
(new_user->name)[MAX_NAME - 1] = '\0';
... | null | null |
63c647635f004bf4898cf351 | 2023-02-08T04:53:26.759Z | Question from Code | v1 | why do I get error with new_post.author = author->name | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
if (check_friends((User *)author, target) == 1) {
return 1;
}
struct post new_post;
new_post.author = author->name;
new_post.... | null | null |
63c647635f004bf4898cf351 | 2023-02-08T04:57:44.821Z | Question from Code | v1 | how to fix error for new_post->author = author->name
| int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
if (check_friends((User *)author, target) == 1) {
return 1;
}
Post *new_post = malloc(sizeof(Post));
new_post->author = author->name;... | null | null |
63c647635f004bf4898cf351 | 2023-02-08T05:05:09.640Z | Question from Code | v1 | why am i getting segmentation fault | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
if (check_friends((User *)author, target) == 1) {
return 1;
}
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author-... | null | null |
63c647635f004bf4898cf351 | 2023-02-08T05:07:14.885Z | Question from Code | v1 | why am I getting segmentation fault | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
if (check_friends((User *)author, target) == 1) {
return 1;
}
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author-... | null | null |
63c647635f004bf4898cf351 | 2023-02-08T05:11:57.321Z | Question from Code | v1 | how to fix error in ew_post->author = malloc(sizeof(char) * MAX_NAME); | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
if (check_friends((User *)author, target) == 1) {
return 1;
}
Post *new_post = malloc(sizeof(Post));
new_post->author = malloc(sizeof... | null | null |
63c647635f004bf4898cf351 | 2023-02-08T05:13:45.509Z | Question from Code | v1 | error in new_post->author = malloc(MAX_NAME * sizeof(char)); | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
if (check_friends((User *)author, target) == 1) {
return 1;
}
Post *new_post = malloc(sizeof(Post));
new_post->author = malloc(MAX_NA... | null | null |
63c647635f004bf4898cf351 | 2023-02-12T00:50:28.733Z | Question from Code | v1 | does this work | int check_friends(User *user1, User *user2) {
int friends = 1;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
friends = 0;
break;
}
}
return friends;
} | null | null |
63c647635f004bf4898cf351 | 2023-02-12T00:51:08.355Z | Question from Code | v1 | why am i getting segmentation fault | int check_friends(User *user1, User *user2) {
int friends = 1;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (strcmp((user1->friends[i])->name, user2->name) == 0) {
friends = 0;
break;
}
}
return friends;
} | null | null |
63c647635f004bf4898cf351 | 2023-02-13T01:44:42.104Z | Question from Code | v1 | why do I have unitialised values | void delete_from_friends(User *user) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (user->friends[i] == NULL) {}
else {
for (int j = 0; j < MAX_FRIENDS; j++) {
User *friends_friend = user->friends[i]->friends[j];
... | null | null |
63c647635f004bf4898cf351 | 2023-02-13T01:47:04.905Z | Question from Code | v1 | why do i have an error with if (friends_friend == NULL) {} | void delete_from_friends(User *user) {
for (int i = 0; i < MAX_FRIENDS; i++) {
if (user->friends[i] == NULL) {}
else {
for (int j = 0; j < MAX_FRIENDS; j++) {
User *friends_friend = user->friends[i]->friends[j];
... | null | null |
63c647635f004bf4898cf351 | 2023-02-22T00:43:09.546Z | Question from Code | v1 | Is there a segmentation fault in this | Rule *parse_file(FILE *fp) {
// Implement this function and remove the stubbed return statement below.
Rule *first_rule_ptr = NULL;
Rule *last_rule_ptr = NULL;
char str[MAXLINE];
while (fgets(str, MAXLINE, fp) != NULL) {
if (str[0] == ' ' || str[0] == '\t' || str[0] == '\n') {}
els... | null | null |
63c647635f004bf4898cf351 | 2023-02-22T00:44:31.528Z | Question from Code | v1 | Is there a segmentation fault in this | Rule *init_rule(char *line) {
Rule *new_rule = malloc(sizeof(Rule));
new_rule->dependencies = NULL;
new_rule->actions = NULL;
new_rule->next_rule = NULL;
char *ptr = strtok(line, " :");
new_rule->target = malloc((sizeof(char) * strlen(ptr)) + 1);
strcpy(new_rule->target, ptr);
new_rule... | null | null |
63c647635f004bf4898cf351 | 2023-02-22T00:45:42.588Z | Question from Code | v1 | Is there a segmentation fault in this | void add_dependencies(Rule **rules_head, char *line) {
char *ptr = strtok((char *)line, " :"); // target name
Rule *curr = *rules_head;
while (curr->next_rule != NULL) {
if (strcmp(curr->target, ptr) == 0) {break;}
else {curr = curr->next_rule;}
}
ptr = strtok(NULL, " ");
whil... | null | null |
63c647635f004bf4898cf351 | 2023-02-22T00:49:50.319Z | Question from Code | v1 | Is there a segmentation fault in this | Rule *find_rule(Rule **rules_ptr, char *name) {
Rule *curr = *rules_ptr;
while(curr->next_rule != NULL) {
if (strcmp(curr->target, name) == 0) {
break;
}
curr = curr->next_rule;
}
if (strcmp(curr->target, name) != 0... | null | null |
63c647635f004bf4898cf351 | 2023-02-22T00:57:51.378Z | Question from Code | v1 | Where are the segmentation faults | int is_target_line(const char *line);
Rule *init_rule(char *line);
void insert_rule(Rule **rules_head, Rule **new_rule);
void add_actions(Rule **last_rule_ptr, char *line);
void add_dependencies(Rule **rules_head, char *line);
Rule *find_rule(Rule **rules_ptr, char *name);
/* Read from the open file fp, and create the... | null | null |
63c647645f004bf4898cf35b | 2023-01-25T21:27:31.768Z | Explain Code | v1 | null | void fib(int **fib_sequence, int count){
*fib_sequence = malloc(sizeof(int)*count);
if (count == 1) {
*fib_sequence[0] = 0;
} else {
*fib_sequence[0] = 0;
*fib_sequence[1] = 1;
for (int i = 2; i < count; i++) {
*fib_sequence[i] = *fib_sequence[i-2] + *fib_sequence[i-1];
}
}
} | null | null |
63c647645f004bf4898cf35b | 2023-01-25T21:28:35.214Z | General Question | v1 | why do I get a segmentation fault | null | null | null |
63c647645f004bf4898cf35b | 2023-01-25T21:30:17.991Z | Help Fix Code | v1 | null | void fib(int **fib_sequence, int count){
*fib_sequence = malloc(sizeof(int)*count);
if (count == 1) {
*fib_sequence[0] = 0;
} else {
*fib_sequence[0] = 0;
*fib_sequence[1] = 1;
for (int i = 2; i < count; i++) {
*fib_sequence[i] = *fib_sequence[i-2] + *fib_sequence[i-1];
}
}
} | generate the first n values in the Fibonacci sequence
| null |
63c647645f004bf4898cf35b | 2023-01-25T21:36:05.238Z | Help Fix Code | v1 | null | void fib(int **fib_sequence, int count){
int *cur = *fib_sequence
cur = malloc(sizeof(int)*count);
if (count == 1) {
cur[0] = 0;
} else {
cur[0] = 0;
cur[1] = 1;
for (int i = 2; i < count; i++) {
cur[i] = cur[i-2] + cur[i-1];
}
}
} | generate the first n values in the Fibonacci sequence | null |
63c647645f004bf4898cf35b | 2023-01-25T21:37:03.455Z | Help Fix Code | v1 | null | void fib(int **fib_sequence, int count){
int *cur = *fib_sequence
cur = malloc(sizeof(int)*count);
if (count == 1) {
*cur[0] = 0;
} else {
*cur[0] = 0;
*cur[1] = 1;
for (int i = 2; i < count; i++) {
*cur[i] = *cur[i-2] + *cur[i-1];
}
}
} | generate the first n values in the Fibonacci sequence | null |
63c647645f004bf4898cf35b | 2023-01-25T21:38:00.702Z | Help Fix Code | v1 | null | void fib(int **fib_sequence, int count){
int *cur = *fib_sequence
cur = malloc(sizeof(int)*count);
if (count == 1) {
cur[0] = 0;
} else {
cur[0] = 0;
cur[1] = 1;
for (int i = 2; i < count; i++) {
cur[i] = *cur[i-2] + *cur[i-1];
}
}
} | generate the first n values in the Fibonacci sequence | null |
63c647645f004bf4898cf35b | 2023-01-25T21:39:23.197Z | Help Fix Code | v1 | null | void fib(int **fib_sequence, int count){
int *cur = *fib_sequence
*cur = malloc(sizeof(int)*count);
if (count == 1) {
cur[0] = 0;
} else {
cur[0] = 0;
cur[1] = 1;
for (int i = 2; i < count; i++) {
cur[i] = cur[i-2] + cur[i-1];
}
}
} | generate the first n values in the Fibonacci sequence | null |
63c647645f004bf4898cf35b | 2023-01-25T21:40:29.438Z | Help Fix Code | v1 | null | void fib(int **fib_sequence, int count){
int *cur = **fib_sequence
cur = malloc(sizeof(int)*count);
if (count == 1) {
cur[0] = 0;
} else {
cur[0] = 0;
cur[1] = 1;
for (int i = 2; i < count; i++) {
cur[i] = cur[i-2] + cur[i-1];
}
}
} | generate the first n values in the Fibonacci sequence | null |
63c647645f004bf4898cf35b | 2023-01-30T21:59:11.935Z | Help Fix Code | v1 | null | int populate_array(int sin, int *sin_array) {
for (int i = 8; i >= 0; i--){
sin_array[i] = sin % 10;
sin = sin / 10;
}
if (sin != 0) {
return 1;
}
else {
return 0;
}
} | It takes an integer and an integer array as its arguments, and returns an integer. This function's job is to populate the given integer array so that it contains the 9 digits of the given integer, in the same order as in the integer. | null |
63c647645f004bf4898cf35b | 2023-01-30T22:00:26.564Z | Help Fix Code | v1 | null | int populate_array(int sin, int *sin_array) {
for (int i = 8; i >= 0; i--){
sin_array[i] = sin % 10;
sin = sin / 10;
}
if (sin == 0) {
return 0;
}
else {
return 1;
}
} | It takes an integer and an integer array as its arguments, and returns an integer. This function's job is to populate the given integer array so that it contains the 9 digits of the given integer, in the same order as in the integer. | null |
63c647645f004bf4898cf35b | 2023-01-30T22:19:32.496Z | Help Fix Code | v1 | null | int check_sin(int *sin_array) {
int sin_total = 0;
for (int i = 0; i < 9; i++){
if (i % 2 == 0){
int result = sin_array[i] * 2; //multiplies every second digit by 2
if (result >= 10) {
sin_total += 1 + (result % 10);
}
else {
sin_total += result;
}
}
else ... | it takes an 9 element integer array representing a candidate SIN number. It returns 0 if the number given is a valid Canadian SIN number, and 1 otherwise. | null |
63c647645f004bf4898cf35b | 2023-02-10T21:56:14.388Z | Explain Code | v1 | null | User *find_user(const char *name, const User *head) {
User *curr_user = (User *) head;
while (curr_user != NULL) {
if (strcmp(curr_user->name, name) == 0) {
return curr_user;
}
}
return NULL;
} | null | null |
63c647645f004bf4898cf35b | 2023-02-10T22:09:34.049Z | Explain Code | v1 | null | void list_users(const User *curr) {
User *curr_user = (User *) curr;
while (curr_user != NULL) {
printf("%s\n", curr_user->name);
curr_user = curr_user->next;
}
} | null | null |
63c647645f004bf4898cf35b | 2023-02-14T19:06:00.310Z | General Question | v1 | how to determine the number of elements in an array | null | null | null |
63c647645f004bf4898cf35b | 2023-02-15T04:49:52.485Z | General Question | v1 | Do we have to assign values to all attributes of a struct when creating a new instance of it | null | null | null |
63c647645f004bf4898cf35b | 2023-02-15T21:10:37.196Z | General Question | v1 | when allocating space for a next pointer in a linked list struct what is the size of the allocation | null | null | null |
63c647645f004bf4898cf35b | 2023-02-17T04:06:47.317Z | Explain Code | v1 | null | char *copy(char *dest, const char *src, int capacity) {
int null_count = 0;
for (int i = 0; i < capacity; i++) {
if (src[i] == '\0') { // When src is less than or equal to capacity to be copied
null_count += (capacity - i);
break;
}
}
if (null_count != 0) {
for (int j = 0; j < cap... | null | null |
63c647645f004bf4898cf35b | 2023-02-17T04:09:24.340Z | Explain Code | v1 | null | char *copy(char *dest, const char *src, int capacity) {
for (int i = 0; i < capacity && src[i] != '\0'; i++) {
dest[i] = src[i];
for ( ; i < capacity; i++) {
dest[i] = '\0';
}
}
return dest;
} | null | null |
63c647645f004bf4898cf35b | 2023-02-17T04:10:50.648Z | Explain Code | v1 | null | char *copy(char *dest, const char *src, int capacity) {
int null_count = 0;
for (int i = 0; i < capacity; i++) {
if (src[i] == '\0') { // When src is less than or equal to capacity to be copied
null_count += (capacity - i);
break;
}
}
if (null_count != 0) {
for (int j = 0; j < cap... | null | null |
63c647645f004bf4898cf35b | 2023-02-28T04:01:01.804Z | General Question | v1 | is the sizeof(int**) equal to sizeof(int*)
| null | null | null |
63c647645f004bf4898cf35b | 2023-03-08T18:27:19.096Z | Help Write Code | v1 | null | null | null | Get parent process to wait for all child process to complete |
63c647645f004bf4898cf35b | 2023-04-02T19:38:32.471Z | General Question | v2 | when a message with newlines is sent to a client from a server should the message end with one network newline or does the network newline replace all newline characters in the message | null | null | null |
63c647645f004bf4898cf35b | 2023-04-06T17:22:07.297Z | General Question | v2 | When to use memset vs when to malloc | null | null | null |
63c647645f004bf4898cf35b | 2023-04-06T20:39:25.321Z | General Question | v2 | how to copy a char array to a char pointer | null | null | null |
63c647645f004bf4898cf35b | 2023-04-06T23:45:58.815Z | General Question | v2 | how to use select | null | null | null |
63c647645f004bf4898cf35b | 2023-04-24T02:38:51.049Z | Help Fix Code | v2 | print list | int *make_list() {
int list[3] = {1, 2, 3};
return list;
}
int main() {
int *l = make_list();
int i;
for (i = 0; i < 3; i++) {
printf("%d\n", l[i]);
}
return 0;
} | null | null |
63c647645f004bf4898cf35b | 2023-04-24T02:48:05.134Z | General Question | v2 | does initializing a char array include the null terminator | null | null | null |
63c647645f004bf4898cf35b | 2023-04-24T02:51:51.169Z | Help Fix Code | v2 | store literal dynamically | char *word = malloc(6 * sizeof(char));
*word = "hello"; | null | null |
63c647645f004bf4898cf35b | 2023-04-24T17:54:28.518Z | General Question | v2 | can strcpy alter string literal | null | null | null |
63c647645f004bf4898cf35b | 2023-04-24T20:11:20.699Z | General Question | v2 | how to guarantee order of output for child processes when forking | null | null | null |
63c647645f004bf4898cf35b | 2023-04-25T03:31:11.151Z | Explain Code | v2 | null | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char **argv) {
int ret;
int sum = 0;
int status;
for (int i = 1; i < argc; i++) {
ret = fork();
if (ret < 0) {
perror("fork");
exit(1);
... | null | null |
63c647645f004bf4898cf35b | 2023-04-25T03:35:19.295Z | General Question | v2 | what is dup2 used for | null | null | null |
63c647645f004bf4898cf35b | 2023-04-25T21:39:20.796Z | Help Fix Code | v2 | print hello world | char *s = "hello world";
char *t = malloc(sizeof(s));
strcpy(t, s);
printf("%s", t); | null | null |
63c647645f004bf4898cf35b | 2023-04-25T21:42:09.850Z | Question from Code | v2 | what happens if we use sizeof(s) in malloc instead of strlen(s) + 1
| char *s = "hello world";
char *t = malloc(sizeof(s));
strcpy(t, s);
printf("%s", t); | null | null |
63c647665f004bf4898cf36f | 2023-03-02T03:02:51.468Z | Question from Code | v1 | modify the program so that the new children do not create additional processes. Only the original parent calls fork. Keep the printf call for all processes. | #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: forkloop <iterations>\n");
exit(1);
}
int iterations = strtol(argv[1], NULL, 10);
for (int i = 0; i < iterations; i++) {
int n = fork();
... | null | null |
63c647665f004bf4898cf36f | 2023-03-02T03:04:17.403Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: forkloop <iterations>\n");
exit(1);
}
int iterations = strtol(argv[1], NULL, 10);
for (int i = 0; i < iterations; i++) {
int n = fork();
... | modify the program so that the new children do not create additional processes. Only the original parent calls fork. Keep the printf call for all processes. | null |
63c647665f004bf4898cf36f | 2023-03-02T03:06:20.878Z | Question from Code | v1 | modify the program so that the new children do not create additional processes. Only the original parent calls fork ITERATIONS times. Keep the printf call for all processes. | #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: forkloop <iterations>\n");
exit(1);
}
int iterations = strtol(argv[1], NULL, 10);
for (int i = 0; i < iterations; i++) {
int n = fork();
... | null | null |
63c647665f004bf4898cf36f | 2023-03-14T01:27:57.390Z | General Question | v2 | how to fork children processes in parallel and make the parent wait for all the childern
| null | null | null |
63c647665f004bf4898cf36f | 2023-03-14T01:30:03.763Z | Help Write Code | v2 | null | null | null | fork 5 child proccess in parallel and make the parent process wait until all child processes have terminated |
63c647665f004bf4898cf36f | 2023-03-14T02:21:51.085Z | General Question | v2 | how to fork childern sequentially and not in parallel | null | null | null |
63c647665f004bf4898cf36f | 2023-03-14T04:24:42.482Z | General Question | v2 | execvp: No such file or directory why am i getting this error | null | null | null |
63c647665f004bf4898cf374 | 2023-01-22T06:21:22.141Z | Question from Code | v1 | Why does this compiling and executing this result in a segmentation fault? | int main(int argc, char **argv) {
// TODO: Verify that command line arguments are valid.
if (argc != 2) {
return 2; //returning with code 2
}
// TODO: Parse arguments and then call the two helpers in sin_helpers.c
// to verify the SIN given as a command line argument.
int sin_number = s... | null | null |
63c647665f004bf4898cf374 | 2023-01-22T06:23:39.600Z | Question from Code | v1 | Does calling this function with appropriate parameters result in a segmentation fault? | int populate_array(int sin, int *sin_array) {
//setting up dummy variables to test whether sin is a 9 digit in
int dummy = sin;
int count = 0;
while (dummy != 0) {
dummy = dummy / 10;
count = count + 1;
}
if (count != 9) { //10 didn't divide into sin exactly 9 times, thus the num... | null | null |
63c647665f004bf4898cf374 | 2023-01-22T06:36:16.925Z | Question from Code | v1 | Will executing main result in a segmentation fault? | #include <stdio.h>
int check_sin(int *sin_array) {
if (sin_array[0] == 0) { //assignment simplification: if it starts with 0 its invalid
return 0;
}
else {
int result[9];
int sum = 0;
for (int i = 0; i < 9; i++) {
if (i % 2 == 0) {
//even indices ... | null | null |
63c647665f004bf4898cf374 | 2023-01-22T06:39:17.378Z | Question from Code | v1 | Does executing main result in a segmentation fault? | #include <stdio.h>
int populate_array(int sin, int *sin_array) {
//setting up dummy variables to test whether sin is a 9 digit in
int dummy = sin;
int count = 0;
while (dummy != 0) {
dummy = dummy / 10;
count = count + 1;
}
if (count != 9) { //10 didn't divide into sin exactly 9 ... | null | null |
63c647665f004bf4898cf374 | 2023-01-22T06:40:04.712Z | Question from Code | v1 | Does executing this code result in a segmentation fault? | #include <stdio.h>
int populate_array(int sin, int *sin_array) {
//setting up dummy variables to test whether sin is a 9 digit in
int dummy = sin;
int count = 0;
while (dummy != 0) {
dummy = dummy / 10;
count = count + 1;
}
if (count != 9) { //10 didn't divide into sin exactly 9 ... | null | null |
63c647665f004bf4898cf374 | 2023-01-22T06:41:09.042Z | Question from Code | v1 | Does executing this code result in a segmentation fault? | #include <stdio.h>
int populate_array(int sin, int *sin_array) {
//setting up dummy variables to test whether sin is a 9 digit in
int dummy = sin;
int count = 0;
while (dummy != 0) {
dummy = dummy / 10;
count = count + 1;
}
if (count != 9) { //10 didn't divide into sin exactly 9 ... | null | null |
63c647665f004bf4898cf374 | 2023-01-22T06:51:03.766Z | Question from Code | v1 | Why does executing this produce a segmentation fault? | #include <stdio.h>
int populate_array(int sin, int *sin_array) {
//setting up dummy variables to test whether sin is a 9 digit in
int dummy = sin;
int count = 0;
while (dummy != 0) {
dummy = dummy / 10;
count = count + 1;
}
if (count != 9) { //10 didn't divide into sin exactly 9 ... | null | null |
63c647665f004bf4898cf374 | 2023-01-22T06:52:22.825Z | Question from Code | v1 | Why does running this produce a segmentation fault? | #include <stdio.h>
int check_sin(int *sin_array) {
if (sin_array[0] == 0) { //assignment simplification: if it starts with 0 its invalid
return 0;
}
else {
int result[9];
int sum = 0;
for (int i = 0; i < 9; i++) {
if (i % 2 == 0) {
//even indices ... | null | null |
63c647665f004bf4898cf374 | 2023-01-22T06:54:07.434Z | Help Fix Code | v1 | null | #include <stdio.h>
int check_sin(int *sin_array) {
if (sin_array[0] == 0) { //assignment simplification: if it starts with 0 its invalid
return 0;
}
else {
int result[9];
int sum = 0;
for (int i = 0; i < 9; i++) {
if (i % 2 == 0) {
//even indices ... | Outputs 1 | null |
63c647665f004bf4898cf374 | 2023-01-22T06:56:43.358Z | Question from Code | v1 | Why does running this result in a segmentation fault? | #include <stdio.h>
int check_sin(int *sin_array) {
if (sin_array[0] == 0) { //assignment simplification: if it starts with 0 its invalid
return 1;
}
else {
int result[9];
int sum = 0;
for (int i = 0; i < 9; i++) {
if (i % 2 == 0) {
//even indices ... | null | null |
63c647665f004bf4898cf374 | 2023-04-23T00:17:23.387Z | Question from Code | v2 | Would the lines of code compile and execute without error always? | int x;
int *p = &x;
printf("%d\n", *p); | null | null |
63c647665f004bf4898cf374 | 2023-04-23T00:19:52.704Z | Question from Code | v2 | Would the code compile and execute without error all the time? | char arr[11] = "Basket";
strcat(arr, "ball");
printf("%s\n", arr); | null | null |
63c647665f004bf4898cf374 | 2023-04-23T00:28:26.919Z | Question from Code | v2 | Would this code always compile and execute without error? | char str[] = "CSC209";
char *s = "CSC209S";
s[6] = '\0';
printf("%d\n", strcmp(str, s)); | null | null |
63c647665f004bf4898cf374 | 2023-04-23T00:50:03.928Z | Question from Code | v2 | Does this code always compile and run without error | char *get_extension(char •str) {
char ext[4];
char *p;
if ((p = strchr(str, '.')) != NULL) {
strncpy(ext, p, 4);
ext[3] = '\0';
return ext;
} else {
return NULL;
}
}
printf("%s\n", get_extension("run.c")); | null | null |
63c647665f004bf4898cf374 | 2023-04-23T00:51:58.020Z | Question from Code | v2 | Does running this code cause any errors such as segmentation fault | char *get_extension(char *str) {
char ext[4];
char *p;
if ((p = strchr(str, '.')) != NULL) {
strncpy(ext, p, 4);
ext[3] = '\0';
return ext;
} else {
return NULL;
}
}
printf("%s\n", get_extension("run.c")); | null | null |
63c647675f004bf4898cf37e | 2023-02-14T19:02:19.184Z | Help Fix Code | v1 | null |
int create_user(const char *name, User **user_ptr_add) {
// Checks if the name fits into the array.
if (strlen(name) >= MAX_NAME) {
return 2;
} else (
User *curr = *user_ptr_add;
User *next = curr -> next;
// While loop to check if the name is already in the list.
w... | /*
* 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 t... | null |
63c647675f004bf4898cf37e | 2023-02-14T19:04:12.190Z | Help Fix Code | v1 | null | User *find_user(const char *name, const User *head) {
const User *curr = head;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
curr = curr -> next;
} else {
return &curr;
}
}
return NULL;
}
| /*
* Return a pointer to the user with this name in
* the list starting with head. Return NULL if no such user exists.
*
* NOTE: You'll likely need to cast a (const User *) to a (User *)
* to satisfy the prototype without warnings.
*/ | null |
63c647675f004bf4898cf37e | 2023-02-14T19:08:05.009Z | Help Fix Code | v1 | null | User *find_user(const char *name, const User *head) {
const User *curr = head;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
curr = curr -> next;
} else {
return curr;
}
}
return NULL;
} | /*
* Return a pointer to the user with this name in
* the list starting with head. Return NULL if no such user exists.
*
* NOTE: You'll likely need to cast a (const User *) to a (User *)
* to satisfy the prototype without warnings.
*/ | null |
63c647675f004bf4898cf37e | 2023-02-14T23:06:09.413Z | Question from Code | v1 | Why is my code giving a segmentation fault? | #define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends... | null | null |
63c647675f004bf4898cf37e | 2023-02-14T23:07:27.395Z | Question from Code | v1 | why is this giving me a segmentation fault | #define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends... | null | null |
63c647675f004bf4898cf37e | 2023-02-14T23:14:30.147Z | Explain Code | v1 | null | #define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends... | null | null |
63c647675f004bf4898cf37e | 2023-02-14T23:15:04.222Z | Question from Code | v1 | why is this giving me a segmentation fault? | #define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends... | null | null |
63c647675f004bf4898cf37e | 2023-02-15T09:08:50.730Z | Question from Code | v1 | WHY AM I GETTING A SEGMENTATION FAULT
| #define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends... | null | null |
63c647675f004bf4898cf37e | 2023-02-15T09:29:12.204Z | Question from Code | v1 | why am i getting a segmentation fault (core dumped) | #define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends... | null | null |
63c647675f004bf4898cf37e | 2023-02-15T09:30:05.608Z | Question from Code | v1 | why am i getting a segmentation fault (core dumped) | #define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends... | null | null |
63c647675f004bf4898cf37e | 2023-02-15T09:40:08.793Z | Question from Code | v1 | why does my while loop run forever | #define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends... | null | null |
63c647675f004bf4898cf37e | 2023-02-15T09:43:16.813Z | Question from Code | v1 | why is my while loop running forever | #define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends... | null | null |
63c647675f004bf4898cf37e | 2023-02-15T10:02:56.564Z | Help Fix Code | v1 | null | #include <time.h>
#define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
s... | /*
* 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 pos... | null |
63c647675f004bf4898cf37e | 2023-02-15T11:39:02.020Z | Help Fix Code | v1 | null | #include <time.h>
#define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
s... | /*
* 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 pos... | null |
63c647675f004bf4898cf37e | 2023-02-15T19:19:56.804Z | Question from Code | v1 | Why am I having a memory leakage from this?
| typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends[MAX_FRIENDS];
struct user *next;
} User;
int print_user(const User *user) {
if (user == NULL) {
return 1;
} else {
... | null | null |
63c647675f004bf4898cf37e | 2023-02-15T19:20:56.252Z | Question from Code | v1 | Why am I having a memory leakage? It seems like the pic is being closed by fclose(pic); | typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends[MAX_FRIENDS];
struct user *next;
} User;
int print_user(const User *user) {
if (user == NULL) {
return 1;
} else {
... | null | null |
63c647675f004bf4898cf37e | 2023-02-15T19:36:02.092Z | Question from Code | v1 | Why am I getting a memory leakage? In function update_pic, the file is being closed using fclose(image); | typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends[MAX_FRIENDS];
struct user *next;
} User;
/*
* Change the filename for the profile pic of the given user.
*
* Return:
* - 0 on s... | null | null |
63c647675f004bf4898cf37e | 2023-02-17T20:23:48.522Z | Help Write Code | v1 | null | null | null | /* Write the copy function to perform exactly as strncpy does, with one
exception: your copy function will guarantee that dest is always
null-terminated. Capacity is expected to be the number of bytes of
memory allocated to dest.
You shoud read the man page to learn how strncpy works.
NOTE: You must wri... |
63c647675f004bf4898cf37e | 2023-02-17T22:39:10.196Z | Explain Code | v1 | null | #include <stdio.h>
#define SIZE 4
#define OVERFLOW 4
int main() {
int index = 0;
int i;
int before[SIZE] = {10, 10, 10, 10};
int a[SIZE] = {0, 0, 0, 0};
int after[SIZE] = {10, 10, 10, 10};
printf("Address of the variables:\n");
for (index = 0; index < SIZE; index++) {
printf("%lx ... | null | null |
63c647695f004bf4898cf38d | 2023-01-27T21:06:10.224Z | Help Fix Code | v1 | null | void fib(int **fib_sequence, int count){
*fib_sequence = malloc(sizeof(int) * count);
if (count >= 1){
(*fib_sequence)[0] = 0;
}
if (count >= 2){
(*fib_sequence)[1] = 1;
}
if (count >= 3){
for (int i = 2; i < count; i++){
... | Building a dynamic array containing the first n elements of the Fibonacci sequence | null |
63c647695f004bf4898cf38d | 2023-01-27T21:13:00.344Z | Help Fix Code | v1 | null | void fib(int **fib_sequence, int count){
*fib_sequence = malloc(sizeof(int) * count);
if (count >= 1){
(*fib_sequence)[0] = 0;
}
if (count >= 2){
(*fib_sequence)[1] = 1;
}
if (count >= 3){
for (int i = 2; i < count; i++){
... | /*
* Define a function void fib(...) below. This function takes parameter n
* and generates the first n values in the Fibonacci sequence. Recall that this
* sequence is defined as:
* 0, 1, 1, 2, 3, 5, ... , fib[n] = fib[n-2] + fib[n-1], ...
* The values should be stored in a dynamically-allocated array co... | null |
63c647695f004bf4898cf38d | 2023-01-29T23:38:28.773Z | Help Fix Code | v1 | null |
int populate_array(int sin, int *sin_array) {
int temp = sin;
int size = 0;
while (temp != 0){
temp /= 10;
size ++;
}
if (size != 9) {
return 1;
}
else {
for (int i = size - 1; i >= 0; i--){
... | /*
* Convert a 9 digit int to a 9 element int array.
*/
| null |
63c647695f004bf4898cf38d | 2023-01-29T23:39:54.539Z | Explain Code | v1 | null |
int populate_array(int sin, int *sin_array) {
int temp = sin;
int size = 0;
while (temp != 0){
temp /= 10;
size ++;
}
if (size != 9) {
return 1;
}
else {
for (int i = size - 1; i >= 0; i--){
... | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.