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
63c648055f004bf4898cf8bf
2023-03-12T21:39:49.962Z
Question from Code
v2
what does this return
char line[50]; strcpy(line, " hello"); if (line[0] == \t) { printf("yay"); }
null
null
63c648055f004bf4898cf8bf
2023-03-12T22:24:14.703Z
Explain Code
v2
null
char *args_to_string(char **args, char *buffer, int size) { buffer[0] = '\0'; int i = 0; while (args[i] != NULL) { strncat(buffer, args[i], size - strlen(buffer)); strncat(buffer, " ", size - strlen(buffer)); i++; } return buffer; }
null
null
63c6480a5f004bf4898cf8ec
2023-02-10T13:19:10.261Z
General Question
v1
explain how fseek works
null
null
null
63c6480a5f004bf4898cf8ec
2023-02-10T19:58:14.882Z
General Question
v1
is there a difference between exit(0) and return 0 from main in C
null
null
null
63c6480a5f004bf4898cf8ec
2023-02-10T20:00:27.960Z
General Question
v1
how do i free malloced memory
null
null
null
63c6480a5f004bf4898cf8ec
2023-03-10T19:51:58.564Z
General Question
v2
explain the C dup2 function
null
null
null
63c6480c5f004bf4898cf8fb
2023-01-31T15:51:12.017Z
Question from Code
v1
what does this print
char **build_month_list(){ // char *month1 = malloc(sizeof(char) * 8); // char *month2 = malloc(sizeof(char) * 9); // char *month3 = malloc(sizeof(char) * 6); // strcpy(month1, "January"); // strcpy(month2, "February"); // strcpy(month3, "March"); char month1[] = "January"; char month2[] = "Fenruary"; char month3[] = "March"; char *month_list[3] = {month1, month2, month3}; return &month_list; } char **months = build_month_list(); for(int i = 0; i < 3; i++) { printf("%s ", months[i]); } printf("\n"); for(int i = 0; i < 3; i++) { months[i][3] = '\0'; printf("%s ", months[i]); } printf("\n");
null
null
63c6480c5f004bf4898cf8fb
2023-02-02T15:16:34.076Z
Question from Code
v1
Have I initialized p1 correctly
#define MAX_AREA_SIZE 16 #include <stdio.h> #include <string.h> #include <stdlib.h> struct faculty { char *name; char area[MAX_AREA_SIZE]; int num_students; }; int main() { // Declare a struct faculty named p1. struct faculty p1; // Initialize p1 to represent Professor Roger Grosse, whose research area // is ML (Machine Learning). He is supervising 11 graduate students. strcpy(p1.name, &"Roger Grose"); strcpy(p1.area, "Machine Learning"); p1.num_students = 11; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-02T15:21:36.177Z
Question from Code
v1
Have I initialized p1 correctly
#define MAX_AREA_SIZE 16 #include <stdio.h> #include <string.h> #include <stdlib.h> struct faculty { char *name; char area[MAX_AREA_SIZE]; int num_students; }; int main() { // Declare a struct faculty named p1. struct faculty p1; // Initialize p1 to represent Professor Roger Grosse, whose research area // is ML (Machine Learning). He is supervising 11 graduate students. char *prof = malloc(sizeof(char) * 12); prof = "Roger Grosse"; p1.name = prof; strcpy(p1.area, "Machine Learning"); p1.num_students = 11; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-02T15:23:11.333Z
Question from Code
v1
Have I initialized p1 correctly
#define MAX_AREA_SIZE 16 #include <stdio.h> #include <string.h> #include <stdlib.h> struct faculty { char *name; char area[MAX_AREA_SIZE]; int num_students; }; int main() { // Declare a struct faculty named p1. struct faculty p1; // Initialize p1 to represent Professor Roger Grosse, whose research area // is ML (Machine Learning). He is supervising 11 graduate students. char *prof = malloc(sizeof(char) * 12); strpy(prof, "Roger Grosse"); p1.name = prof; strcpy(p1.area, "Machine Learning"); p1.num_students = 11; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-03T02:41:13.146Z
Question from Code
v1
Why does my truncate function not change s
#include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters that were removed. If s has n or fewer characters, s is unchanged and the function returns 0. For example, if s is the string "function" and n is 3, then truncate() changes s to the string "fun" and returns 5. */ int truncate(char *s, int n){ // char *temp = s; int length = strlen(s); if (length <= n){ return 0; } else{ s = malloc(sizeof(char) * n); s[n] = "\0"; return length - n; } } int main(int argc, char **argv) { /* Do not change the main function */ if (argc != 3) { fprintf(stderr, "Usage: truncate number string\n"); return 1; } int amt = strtol(argv[1], NULL, 10); char *target = argv[2]; int soln_val = truncate(target, amt); printf("%d %s\n", soln_val, target); return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-03T02:43:39.994Z
Question from Code
v1
How do I change the value of s
#include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters that were removed. If s has n or fewer characters, s is unchanged and the function returns 0. For example, if s is the string "function" and n is 3, then truncate() changes s to the string "fun" and returns 5. */ int truncate(char *s, int n){ // char *temp = s; int length = strlen(s); if (length <= n){ return 0; } else{ // s = malloc(sizeof(char) * n); s[n] = "\0"; return length - n; } } int main(int argc, char **argv) { /* Do not change the main function */ if (argc != 3) { fprintf(stderr, "Usage: truncate number string\n"); return 1; } int amt = strtol(argv[1], NULL, 10); char *target = argv[2]; int soln_val = truncate(target, amt); printf("%d %s\n", soln_val, target); return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-03T02:51:45.702Z
Question from Code
v1
How do I create the function truncate from the information in lines 6 to 12
#include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters that were removed. If s has n or fewer characters, s is unchanged and the function returns 0. For example, if s is the string "function" and n is 3, then truncate() changes s to the string "fun" and returns 5. */ int truncate(char *s, int n){ // char *temp = s; int length = strlen(s); if (length <= n){ return 0; } else{ // s = malloc(sizeof(char) * n); s[n] = "\0"; return length - n; } } int main(int argc, char **argv) { /* Do not change the main function */ if (argc != 3) { fprintf(stderr, "Usage: truncate number string\n"); return 1; } int amt = strtol(argv[1], NULL, 10); char *target = argv[2]; int soln_val = truncate(target, amt); printf("%d %s\n", soln_val, target); return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-03T02:52:46.568Z
Question from Code
v1
How do I change s in truncate to a different string
#include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters that were removed. If s has n or fewer characters, s is unchanged and the function returns 0. For example, if s is the string "function" and n is 3, then truncate() changes s to the string "fun" and returns 5. */ int truncate(char *s, int n){ // char *temp = s; int length = strlen(s); if (length <= n){ return 0; } else{ // s = malloc(sizeof(char) * n); s[n] = "\0"; return length - n; } } int main(int argc, char **argv) { /* Do not change the main function */ if (argc != 3) { fprintf(stderr, "Usage: truncate number string\n"); return 1; } int amt = strtol(argv[1], NULL, 10); char *target = argv[2]; int soln_val = truncate(target, amt); printf("%d %s\n", soln_val, target); return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-03T02:53:46.594Z
Help Fix Code
v1
null
#include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters that were removed. If s has n or fewer characters, s is unchanged and the function returns 0. For example, if s is the string "function" and n is 3, then truncate() changes s to the string "fun" and returns 5. */ int truncate(char *s, int n){ // char *temp = s; int length = strlen(s); if (length <= n){ return 0; } else{ // s = malloc(sizeof(char) * n); s[n] = "\0"; return length - n; } } int main(int argc, char **argv) { /* Do not change the main function */ if (argc != 3) { fprintf(stderr, "Usage: truncate number string\n"); return 1; } int amt = strtol(argv[1], NULL, 10); char *target = argv[2]; int soln_val = truncate(target, amt); printf("%d %s\n", soln_val, target); return 0; }
Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters that were removed. If s has n or fewer characters, s is unchanged and the function returns 0. For example, if s is the string "function" and n is 3, then truncate() changes s to the string "fun" and returns 5.
null
63c6480c5f004bf4898cf8fb
2023-02-09T06:02:16.610Z
Question from Code
v1
why do I get a segmentation fault in this program
int create_user(const char *name, User **user_ptr_add) { if (strlen(name) >= 32){ return 2; } User *curr = *user_ptr_add; while(curr->next != NULL){ if (strcmp(name, curr->name) == 0){ return 1; } curr = curr->next; } User new_person; strcpy(new_person.name, name); curr->next = &new_person; return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-09T06:15:40.485Z
Question from Code
v1
Why am I receiving a segmentation fault
int create_user(const char *name, User **user_ptr_add) { if (strlen(name) >= 32){ return 2; } User *curr = *user_ptr_add; while(curr->next != NULL){ if (strcmp(name, curr->name) == 0){ return 1; } curr = curr->next; } User *new_person; new_person = malloc(sizeof(User)); strcpy(new_person->name, name); curr->next = new_person; return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-10T19:14:21.392Z
Question from Code
v1
What is the error in my code
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { struct pixel *values = malloc(sizeof(struct pixel*) * height); for(int i = 0; i < height; i++){ struct pixel* values[i] = malloc(sizeof(unsigned char) * 3); } fseek(image, pixel_array_offset, SEEK_SET); for(int i = 0; i < height; i++){ for(int j = 0; j < 3; j++){ unsigned char val; fread(val, sizeof(unsigned char), 1, image); values[i][j] = val; } } return &values[0]; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-11T18:50:37.176Z
Question from Code
v1
What is wrong with my code
int make_friends(const char *name1, const char *name2, User *head) { User user1 = NULL; User user2 = NULL; while(head != NULL){ if (strcmp(name1, head->name) == 0){ user1 = *head; } else if (strcmp(name2, head->name) == 0){ user2 = *head; } else{ head = head->next; } } if ((user1 == NULL) || (user2 == NULL)){ return 4; } if (strcmp(name1, name2) == 0){ return 3; } if ((strlen(user1.friends) == 10) || (strlen(user2.friends) == 10)){ return 2; } for(int i = 0; i < strlen(user1.friends); i++){ if (strcmp(name2, user1.friends[i]->name) == 0){ for(int j = 0; j < strlen(user2.friends); j++){ if (strcmp(name1, user2.friends[j]->name) == 0){ return 1; } } } } user1.friends[strlen(user1.friends)] = &user2; user2.friends[strlen(user2.friends)] = &user1; return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-11T19:18:47.862Z
Question from Code
v1
What's wrong with my code
int make_friends(const char *name1, const char *name2, User *head) { User *user1 = NULL; User *user2 = NULL; while(head != NULL){ if (strcmp(name1, head->name) == 0){ user1 = head; } else if (strcmp(name2, head->name) == 0){ user2 = head; } else{ head = head->next; } } if ((user1 == NULL) || (user2 == NULL)){ return 4; } if (strcmp(name1, name2) == 0){ return 3; } if ((strlen(user1.friends) == 10) || (strlen(user2.friends) == 10)){ return 2; } for(int i = 0; i < strlen(user1.friends); i++){ if (strcmp(name2, user1.friends[i]->name) == 0){ for(int j = 0; j < strlen(user2.friends); j++){ if (strcmp(name1, user2.friends[j]->name) == 0){ return 1; } } } } user1.friends[strlen(user1.friends)] = &user2; user2.friends[strlen(user2.friends)] = &user1; return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-11T19:22:00.554Z
Question from Code
v1
What's wrong with my code
int make_friends(const char *name1, const char *name2, User *head) { User *user1 = NULL; User *user2 = NULL; while(head != NULL){ if (strcmp(name1, head->name) == 0){ user1 = head; } else if (strcmp(name2, head->name) == 0){ user2 = head; } else{ head = head->next; } } if ((user1 == NULL) || (user2 == NULL)){ return 4; } if (strcmp(name1, name2) == 0){ return 3; } if ((strlen(user1.friends) == 10) || (strlen(user2.friends) == 10)){ return 2; } for(int i = 0; i < strlen(user1.friends); i++){ if (strcmp(name2, user1.friends[i]->name) == 0){ for(int j = 0; j < strlen(user2.friends); j++){ if (strcmp(name1, user2.friends[j]->name) == 0){ return 1; } } } } user1.friends[strlen(user1.friends)] = user2; user2.friends[strlen(user2.friends)] = user1; return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-13T22:12:22.292Z
Question from Code
v1
What does my code print
#define SUPERVISOR(regular) regular + 5 int main() { int regular_pay = 20; int hours_worked = 10; printf("pay is %d\n", (hours_worked * SUPERVISOR(regular_pay))); }
null
null
63c6480c5f004bf4898cf8fb
2023-02-15T00:06:05.191Z
Question from Code
v1
Why is it that the date stored in now is not correct?
int make_post(const User *author, User *target, char *contents) { if ((author == NULL) || (target == NULL)){ return 2; } int author_length = 0; int target_length = 0; for (int i = 0; i < 10; i++){ if (author->friends[i] != NULL){ author_length = author_length + 1; } } for (int i = 0; i < 10; i++){ if (author->friends[i] != NULL){ target_length = target_length + 1; } } int are_friends = 0; // are_friends = 1 for no and 0 for yes for (int i = 0; i < author_length; i++){ if (strcmp(target->name, author->friends[i]->name) == 0){ for (int j = 0; j < target_length; j++){ if (strcmp(author->name, target->friends[i]->name) == 0){ are_friends = 1; } } } } if (are_friends == 0){ return 1; } Post *new_first_post = malloc(sizeof(Post)); strcpy(new_first_post->author, author->name); new_first_post->contents = contents; time_t now = time(NULL); new_first_post->date = &now; new_first_post->next = target->first_post; target->first_post = new_first_post; return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-15T08:37:50.817Z
Question from Code
v1
Why do I get a segmentation fault
int delete_user(const char *name, User **user_ptr_del) { User *curr = *user_ptr_del; User *prev = NULL; while((strcmp(name, curr->name) != 0) || (curr != NULL)){ prev = curr; curr = curr->next; } if (curr == NULL){ return 1; } if (prev == NULL){ curr->next = NULL; } else{ prev->next = curr->next; curr->next = NULL; } int length = 0; for(int i = 0; i < 10; i++){ if (curr->friends[i] != NULL){ length = length + 1; } } for(int i = 0; i < length; i++){ int length2 = 0; for (int a = 0; a < 10; a++){ if(curr->friends[i]->friends[a] != NULL){ length2 = length2 + 1; } } for(int j = 0; j < length2; j++){ if(strcmp(name, curr->friends[i]->friends[j]->name) == 0){ for (int x = j; x < length2 - 1; x++){ curr->friends[i]->friends[x] = curr->friends[i]->friends[x + 1]; } curr->friends[i]->friends[length2 - 1] = NULL; } } } for(int i = 0; i < 10; i++){ // if (curr->friends[i] == NULL){ // free(curr->friends[i]); // } free(curr->friends[i]); } // Post *curr3 = curr->first_post; while(curr->first_post != NULL){ free(curr->first_post->author); free(curr->first_post->contents); free(curr->first_post->date); curr->first_post = curr->first_post->next; } curr->first_post->next = NULL; free(curr->name); free(curr->profile_pic); free(curr->friends); free(curr->first_post); free(curr); return 0;
null
null
63c6480c5f004bf4898cf8fb
2023-02-15T08:39:51.023Z
Question from Code
v1
Why am I getting a segmentation fault
int delete_user(const char *name, User **user_ptr_del) { User *curr = *user_ptr_del; User *prev = NULL; while((strcmp(name, curr->name) != 0) || (curr != NULL)){ prev = curr; curr = curr->next; } if (curr == NULL){ return 1; } if (prev == NULL){ curr->next = NULL; } else{ prev->next = curr->next; curr->next = NULL; } int length = 0; for(int i = 0; i < 10; i++){ if (curr->friends[i] != NULL){ length = length + 1; } } for(int i = 0; i < length; i++){ int length2 = 0; for (int a = 0; a < 10; a++){ if(curr->friends[i]->friends[a] != NULL){ length2 = length2 + 1; } } for(int j = 0; j < length2; j++){ if(strcmp(name, curr->friends[i]->friends[j]->name) == 0){ for (int x = j; x < length2 - 1; x++){ curr->friends[i]->friends[x] = curr->friends[i]->friends[x + 1]; } curr->friends[i]->friends[length2 - 1] = NULL; } } } for(int i = 0; i < 10; i++){ if (curr->friends[i] != NULL){ free(curr->friends[i]); } } // Post *curr3 = curr->first_post; while(curr->first_post != NULL){ free(curr->first_post->author); free(curr->first_post->contents); free(curr->first_post->date); curr->first_post = curr->first_post->next; } curr->first_post->next = NULL; free(curr->name); free(curr->profile_pic); free(curr->friends); free(curr->first_post); free(curr); return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-02-15T09:09:51.577Z
Question from Code
v1
Why do I get an invalid pointer
int delete_user(const char *name, User **user_ptr_del) { User *curr = *user_ptr_del; User *prev = NULL; while ((curr != NULL) && (strcmp(name, curr->name) != 0)) { prev = curr; curr = curr->next; } if (curr == NULL){ return 1; } if (prev == NULL) { *user_ptr_del = curr->next; } else { prev->next = curr->next; curr->next = NULL; } int length = 0; for(int i = 0; (i < 10) && (curr->friends[i] != NULL); i++){ length = length + 1; } for(int i = 0; (i < length) && (curr->friends[i] != NULL); i++){ int length2 = 0; for (int a = 0; (a < 10) && (curr->friends[i]->friends[a] != NULL); a++){ length2 = length2 + 1; } for(int j = 0; j < length2; j++){ if(strcmp(name, curr->friends[i]->friends[j]->name) == 0){ for (int x = j; x < length2 - 1; x++){ curr->friends[i]->friends[x] = curr->friends[i]->friends[x + 1]; } curr->friends[i]->friends[length2 - 1] = NULL; } } } printf("good"); Post *curr3 = curr->first_post; while (curr3 != NULL) { free(curr3->author); free(curr3->contents); free(curr3->date); Post *next_post = curr3->next; free(curr3); curr3 = next_post; } printf("good"); free(curr->name); free(curr->profile_pic); for (int i = 0; i < 10; i++) { if (curr->friends[i] != NULL) { free(curr->friends[i]); } } free(curr); return 0;
null
null
63c6480c5f004bf4898cf8fb
2023-02-15T09:10:43.205Z
Question from Code
v1
Am I demallocing correctly
int delete_user(const char *name, User **user_ptr_del) { User *curr = *user_ptr_del; User *prev = NULL; while ((curr != NULL) && (strcmp(name, curr->name) != 0)) { prev = curr; curr = curr->next; } if (curr == NULL){ return 1; } if (prev == NULL) { *user_ptr_del = curr->next; } else { prev->next = curr->next; curr->next = NULL; } int length = 0; for(int i = 0; (i < 10) && (curr->friends[i] != NULL); i++){ length = length + 1; } for(int i = 0; (i < length) && (curr->friends[i] != NULL); i++){ int length2 = 0; for (int a = 0; (a < 10) && (curr->friends[i]->friends[a] != NULL); a++){ length2 = length2 + 1; } for(int j = 0; j < length2; j++){ if(strcmp(name, curr->friends[i]->friends[j]->name) == 0){ for (int x = j; x < length2 - 1; x++){ curr->friends[i]->friends[x] = curr->friends[i]->friends[x + 1]; } curr->friends[i]->friends[length2 - 1] = NULL; } } } printf("good"); Post *curr3 = curr->first_post; while (curr3 != NULL) { free(curr3->author); free(curr3->contents); free(curr3->date); Post *next_post = curr3->next; free(curr3); curr3 = next_post; } printf("good"); free(curr->name); free(curr->profile_pic); for (int i = 0; i < 10; i++) { if (curr->friends[i] != NULL) { free(curr->friends[i]); } } free(curr); return 0;
null
null
63c6480c5f004bf4898cf8fb
2023-03-03T17:31:29.137Z
Question from Code
v1
Why am I getting a warning when I try to wait for the child process to finish (line 24)
#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); int pid = getpid(); for (int i = 0; i < iterations; i++) { int n = fork(); if (n < 0){ perror("fork"); exit(1); } else if (n == 0){ printf("ppid = %d, pid = %d, i = %d\n", getppid(), getpid(), i); exit(0); } else{ wait(NULL); } } if (getpid() == pid){ printf("ppid = %d, pid = %d, i = %d\n", getppid(), getpid(), iterations); } return 0; }
null
null
63c6480c5f004bf4898cf8fb
2023-03-03T17:32:24.997Z
Question from Code
v1
what should I put in the parameter of wait so that the child process finishes first (line 24)
#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); int pid = getpid(); for (int i = 0; i < iterations; i++) { int n = fork(); if (n < 0){ perror("fork"); exit(1); } else if (n == 0){ printf("ppid = %d, pid = %d, i = %d\n", getppid(), getpid(), i); exit(0); } else{ wait(NULL); } } if (getpid() == pid){ printf("ppid = %d, pid = %d, i = %d\n", getppid(), getpid(), iterations); } return 0; }
null
null
63c648105f004bf4898cf919
2023-03-15T15:47:31.463Z
Question from Code
v2
Why am I getting a segmentation fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(line, ":"); head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T15:56:54.199Z
Question from Code
v2
Why does this produce a segmentation fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(&(line[0]), ":"); head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T15:59:34.455Z
Question from Code
v2
Why is there a segmentation fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(&(line[0]), ":"); if (head_rule != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T16:03:07.329Z
Question from Code
v2
Why am I still getting a segmentation fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(&(line[0]), ":"); if (head_rule != NULL && head_rule->target != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T16:37:58.823Z
Question from Code
v2
What is causing the seg fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(&(line[0]), ":"); if (head_rule != NULL && head_rule->target != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T16:38:55.058Z
Question from Code
v2
Why does strtok produce a seg fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(&(line[0]), ":"); if (head_rule != NULL && head_rule->target != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T16:42:03.821Z
Question from Code
v2
Why does line 12 give a seg fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(line, ":"); if (head_rule != NULL && head_rule->target != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T16:42:58.783Z
Question from Code
v2
Why does strtok give a seg fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(line, ":"); if (head_rule != NULL && head_rule->target != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T16:47:18.826Z
Question from Code
v2
Why does line 24 produce a seg fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(line, ":"); if (head_rule != NULL && head_rule->target != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } fgets(line, MAXLINE, fp); while (&(line[0]) != NULL) { if (is_comment_or_empty(line) == 0 && line[0] != '\t') { token = strtok(&(line[0]), ":"); Rule *new_rule = add_rule(prev_rule); head_rule->target = malloc(sizeof(token)); strcpy(new_rule->target, token); prev_rule->next_rule = new_rule; prev_rule = new_rule; } fgets(line, MAXLINE, fp); token = strtok(&(line[0]), " "); } return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T16:51:04.994Z
Question from Code
v2
Why does strcpy in line 24 cause a seg fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(line, ":"); if (head_rule != NULL && head_rule->target != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } fgets(line, MAXLINE, fp); while (&(line[0]) != NULL) { if (is_comment_or_empty(line) == 0 && line[0] != '\t') { token = strtok(&(line[0]), ":"); Rule *new_rule = add_rule(prev_rule); head_rule->target = malloc(sizeof(token)); strcpy(new_rule->target, token); prev_rule->next_rule = new_rule; prev_rule = new_rule; } fgets(line, MAXLINE, fp); token = strtok(&(line[0]), " "); } return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T17:00:33.628Z
Question from Code
v2
Why does line 24 give a seg fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(line, ":"); if (head_rule != NULL && head_rule->target != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } fgets(line, MAXLINE, fp); while (&(line[0]) != NULL) { if (is_comment_or_empty(line) == 0 && line[0] != '\t') { token = strtok(&(line[0]), ":"); Rule *new_rule = add_rule(prev_rule); head_rule->target = malloc(strlen(token) + 1); strcpy(new_rule->target, token); prev_rule->next_rule = new_rule; prev_rule = new_rule; } fgets(line, MAXLINE, fp); token = strtok(&(line[0]), " "); } return result; }
null
null
63c648105f004bf4898cf919
2023-03-15T17:01:44.910Z
Question from Code
v2
Why does line 24 give a seg fault?
Rule *parse_file(FILE *fp) { Rule *result; Rule *prev_rule; char line[MAXLINE]; fgets(&(line[0]), MAXLINE, fp); Rule *head_rule = malloc(sizeof(Rule)); result = head_rule; prev_rule = head_rule; char *token = strtok(line, ":"); if (head_rule != NULL && head_rule->target != NULL) { head_rule->target = malloc(strlen(token)); strcpy(head_rule->target, token); } fgets(line, MAXLINE, fp); while (&(line[0]) != NULL) { if (is_comment_or_empty(line) == 0 && line[0] != '\t') { token = strtok(&(line[0]), ":"); Rule *new_rule = add_rule(prev_rule); if (head_rule != NULL) { head_rule->target = malloc(strlen(token) + 1); strcpy(new_rule->target, token); } prev_rule->next_rule = new_rule; prev_rule = new_rule; } fgets(line, MAXLINE, fp); token = strtok(&(line[0]), " "); } return result; }
null
null
63c648115f004bf4898cf928
2023-02-08T19:38:24.412Z
General Question
v1
how to initialize the pointer allocated to point to heap-allocated space for an entire row of pixel data.
null
null
null
63c648115f004bf4898cf928
2023-02-08T19:39:16.902Z
Question from Code
v1
how to initialize the pointer allocated to point to heap-allocated space for an entire row of pixel data.
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { struct pixel **array = malloc (sizeof(struct pixel *) * height); }
null
null
63c648115f004bf4898cf928
2023-02-08T19:43:21.201Z
Help Fix Code
v1
null
void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { fseek(image, 10, SEEK_SET); error = fread(pixel_array_offset,4,1,image); fseek(image, 18, SEEK_SET); error = fread(width,4,1,image); fseek(image, 22, SEEK_SET); error = fread(height,4,1,image); }
byte 10 - 13 should be the value for pixel_array_offset, byte 18 - 21 should be the value for width and byte 22-25 should be the height.
null
63c648115f004bf4898cf928
2023-02-08T19:45:07.186Z
Help Fix Code
v1
null
void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { fseek(image, 10, SEEK_SET); error = fread(pixel_array_offset,4,1,image); fseek(image, 18, SEEK_SET); error = fread(width,4,1,image); fseek(image, 22, SEEK_SET); error = fread(height,4,1,image); }
pixel_array_offset should assign the value in byte 10 - 13 of the file, byte 18 - 21 should be the value for width should be assigned the value of byte 18 - 21 of the file, height should be assign the value of byte 22-25 of the file
null
63c648125f004bf4898cf932
2023-01-28T15:56:39.718Z
Help Fix Code
v1
null
char cmd_permission[10]; cmd_permission = argv[2];
assign arg[v] to cmd_permission
null
63c648125f004bf4898cf932
2023-01-28T15:57:40.282Z
General Question
v1
how to assign string to char array
null
null
null
63c648125f004bf4898cf932
2023-01-28T16:04:18.432Z
General Question
v1
assign string to char array without strcpy()
null
null
null
63c648125f004bf4898cf932
2023-02-10T00:09:14.977Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { struct pixel *pixel_arr[height]; }
initialize an array with height elements
null
63c648125f004bf4898cf932
2023-02-12T20:03:17.699Z
General Question
v1
how to use gdb with multiple files
null
null
null
63c648125f004bf4898cf932
2023-02-12T20:03:59.650Z
General Question
v1
how to use gdb
null
null
null
63c648125f004bf4898cf932
2023-02-12T20:05:55.861Z
General Question
v1
how to run next line in gdb
null
null
null
63c648125f004bf4898cf932
2023-02-12T22:27:33.276Z
General Question
v1
what does fopen() return if file does not exist?
null
null
null
63c648125f004bf4898cf932
2023-02-12T22:34:00.817Z
General Question
v1
how to go back in gdp?
null
null
null
63c648125f004bf4898cf932
2023-02-13T00:40:02.155Z
General Question
v1
can i pass a User * type into a const User * type?
null
null
null
63c648125f004bf4898cf932
2023-02-13T02:20:24.893Z
General Question
v1
can you negative index an array?
null
null
null
63c648125f004bf4898cf932
2023-02-13T02:26:22.241Z
General Question
v1
can you initialise an array of 0 elements?
null
null
null
63c648125f004bf4898cf932
2023-02-13T02:32:39.532Z
General Question
v1
how can i set all elements of an array to NULL?
null
null
null
63c648125f004bf4898cf932
2023-02-13T15:45:43.838Z
General Question
v1
how to run until breakpoint in gdb?
null
null
null
63c648125f004bf4898cf932
2023-02-13T16:58:34.436Z
General Question
v1
can i set a string to NULL?
null
null
null
63c648125f004bf4898cf932
2023-02-13T17:20:41.606Z
General Question
v1
ho to print contents of a text file with fopen?
null
null
null
63c648125f004bf4898cf932
2023-02-13T17:32:46.109Z
General Question
v1
do you have to fclose on a NULL stream?
null
null
null
63c648125f004bf4898cf932
2023-02-13T17:38:02.878Z
General Question
v1
fgets return value?
null
null
null
63c648125f004bf4898cf932
2023-02-13T18:23:14.417Z
General Question
v1
how to define char array in function parameter?
null
null
null
63c648125f004bf4898cf932
2023-02-13T18:48:19.484Z
General Question
v1
how to use ctime?
null
null
null
63c648125f004bf4898cf932
2023-02-15T14:13:03.156Z
Help Fix Code
v1
null
*curr_time = time(NULL);
assign the pointer value to time(NULL)
null
63c648125f004bf4898cf932
2023-02-15T14:14:24.613Z
Help Fix Code
v1
null
time_t *curr_time = malloc(sizeof(time_t)); curr_time = time(NULL);
assign the pointer curr_time to the address of time(NULL)
null
63c648125f004bf4898cf932
2023-03-01T23:16:49.762Z
General Question
v1
does fgets() read empty lines?
null
null
null
63c648125f004bf4898cf932
2023-03-10T22:09:55.786Z
General Question
v2
what is the purpose of NULL passed to execl()?
null
null
null
63c648125f004bf4898cf932
2023-03-10T22:37:05.485Z
General Question
v2
how to write multiple values to a pipe?
null
null
null
63c648125f004bf4898cf932
2023-03-11T18:43:14.770Z
General Question
v2
how can i use strtok() to split on spaces and tabs?
null
null
null
63c648125f004bf4898cf932
2023-03-11T18:49:18.814Z
General Question
v2
how to use strtok() to find comments?
null
null
null
63c648125f004bf4898cf932
2023-03-12T01:13:54.786Z
General Question
v2
can i index a char *pointer?
null
null
null
63c648125f004bf4898cf932
2023-03-12T01:33:20.122Z
General Question
v2
does fgets() read \n character for blank lines?
null
null
null
63c648125f004bf4898cf932
2023-03-12T01:52:16.766Z
General Question
v2
how can i tell if a string starts with a \t tab character?
null
null
null
63c648125f004bf4898cf932
2023-03-12T14:09:32.905Z
General Question
v2
can you compare characters with == ?
null
null
null
63c648125f004bf4898cf932
2023-03-12T19:53:27.868Z
General Question
v2
can i set a struct attribute to a read-only string in a helper function?
null
null
null
63c648125f004bf4898cf932
2023-03-13T01:42:18.355Z
General Question
v2
when should i malloc a string vs just assign it in a helper function?
null
null
null
63c648125f004bf4898cf932
2023-03-13T18:26:20.727Z
General Question
v2
when passing a struct to a function to be modified, should i pass a pointer to struct or a pointer to pointer to struct?
null
null
null
63c648125f004bf4898cf932
2023-03-13T18:40:09.445Z
General Question
v2
how to call strtok repeatedly on the same line?
null
null
null
63c648125f004bf4898cf932
2023-03-14T02:22:21.090Z
General Question
v2
is there a function to count the number of words in a string?
null
null
null
63c648125f004bf4898cf932
2023-03-14T02:42:42.654Z
General Question
v2
can you initailize an array of size 0?
null
null
null
63c648125f004bf4898cf932
2023-03-14T03:28:15.439Z
General Question
v2
what is returned if strtok() is called on a whitespace line?
null
null
null
63c648125f004bf4898cf932
2023-03-14T03:43:32.687Z
General Question
v2
how to strip a string of specific characters?
null
null
null
63c648125f004bf4898cf932
2023-03-14T03:47:37.625Z
General Question
v2
does strtok remove tabs when passed " "?
null
null
null
63c648125f004bf4898cf932
2023-03-14T03:49:21.068Z
General Question
v2
what's the \r character?
null
null
null
63c648125f004bf4898cf932
2023-03-14T05:06:17.661Z
General Question
v2
what happens if you call strtok() with NULL?
null
null
null
63c648125f004bf4898cf932
2023-03-14T14:42:21.844Z
General Question
v2
how to strip \n character with gets?
null
null
null
63c648125f004bf4898cf932
2023-03-14T14:43:04.270Z
General Question
v2
how to strip \n character with fgets?
null
null
null
63c648125f004bf4898cf932
2023-03-14T15:14:31.866Z
General Question
v2
when does strtok end?
null
null
null
63c648125f004bf4898cf932
2023-03-14T18:38:27.601Z
General Question
v2
does strncpy copy the null terminator?
null
null
null
63c648125f004bf4898cf932
2023-03-14T18:42:13.607Z
General Question
v2
how to edit value of a dynamically allocated string?
null
null
null
63c648125f004bf4898cf932
2023-03-14T23:30:07.098Z
General Question
v2
how to get the size of an array?
null
null
null
63c648125f004bf4898cf932
2023-03-14T23:46:57.591Z
General Question
v2
what type does malloc(sizeof(char *)) return?
null
null
null
63c648125f004bf4898cf932
2023-03-15T00:32:10.411Z
General Question
v2
can i check if a variables been declaared or not?
null
null
null
63c648125f004bf4898cf932
2023-03-15T04:06:28.172Z
General Question
v2
how to use strchr to replace a character with another?
null
null
null
63c648125f004bf4898cf932
2023-03-15T04:08:42.976Z
Help Fix Code
v2
replace \r character with \0
if ((newline_index = strchr(curr_line, '\r')) != NULL) { *newline_index = '\0'; }
null
null
63c648125f004bf4898cf932
2023-03-15T04:31:41.976Z
General Question
v2
how to clear a character array?
null
null
null
63c648125f004bf4898cf932
2023-03-15T13:21:26.656Z
General Question
v2
can you set a character array to NULL?
null
null
null
63c648125f004bf4898cf932
2023-03-17T16:12:21.803Z
General Question
v2
how to write ineteger to a binary file?
null
null
null