user_id
stringlengths
24
24
time
stringlengths
24
24
feature_type
stringclasses
5 values
feature_version
stringclasses
2 values
input_question
stringlengths
1
1.24k
input_code
stringlengths
2
18.5k
input_intention
stringlengths
1
2.48k
input_task_description
stringlengths
18
3.32k
63c648a65f004bf4898cfe6e
2023-02-08T03:46:16.613Z
Question from Code
v1
allocate space for m `struct pixel *` values, where m is the * height of the image. Each pointer will eventually point to one row of * pixel data.
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) {
null
null
63c648a65f004bf4898cfe6e
2023-02-08T03:48:16.549Z
Question from Code
v1
allocate an array of struct pixel * pointers, each of which will point to a row of pixels.
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) {
null
null
63c648a65f004bf4898cfe6e
2023-02-08T03:48:48.390Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) {
allocate an array of struct pixel * pointers, each of which will point to a row of pixels.
null
63c648a65f004bf4898cfe6e
2023-02-08T03:49:57.269Z
Question from Code
v1
allocate space for m `struct pixel *` values, where m is the * height of the image. Each pointer will eventually point to one row of * pixel data.
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { // 1. struct pixel *pixels; // 2. for (int i=0; i < height; i++) { pixels[i] = malloc(sizeof(struct pixel) * width); }
null
null
63c648a65f004bf4898cfe6e
2023-02-08T03:50:28.205Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { // 1. struct pixel *pixels; // 2. for (int i=0; i < height; i++) { pixels[i] = malloc(sizeof(struct pixel) * width); }
allocate space for m `struct pixel *` values, where m is the height of the image. Each pointer will eventually point to one row of pixel data.
null
63c648a65f004bf4898cfe6e
2023-02-08T03:52:00.981Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { // 1. struct pixel *pixels = malloc(sizeof(struct pixel) * height); // 2. for (int i=0; i < height; i++) { pixels[i] = malloc(sizeof(struct pixel) * width); }
For each pointer you just allocated, initialize it to point to heap-allocated space for an entire row of pixel data.
null
63c648a65f004bf4898cfe6e
2023-02-08T03:54:23.238Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { // 1. struct pixel **pixels = malloc(sizeof(struct pixel *) * height); // 2. for (int i=0; i < height; i++) { pixels[i] = malloc(sizeof(struct pixel) * width); } // 3. while (sizeof(struct pixel) == 3) { } }
check that sizeof(struct pixel) == 3
null
63c648a65f004bf4898cfe6e
2023-02-08T03:55:18.226Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { // 1. struct pixel **pixels = malloc(sizeof(struct pixel *) * height); // 2. for (int i=0; i < height; i++) { pixels[i] = malloc(sizeof(struct pixel) * width); } // 3. while (sizeof(struct pixel) == 3) { } }
Use the given file and pixel_array_offset to initialize the actual struct pixel values
null
63c648a65f004bf4898cfe6e
2023-02-08T04:02:57.983Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { // 1. struct pixel **pixels = malloc(sizeof(struct pixel *) * height); // 2. for (int i=0; i < height; i++) { pixels[i] = malloc(sizeof(struct pixel) * width); } // 3. while (sizeof(struct pixel) == 3) { } }
free the program's dynamically allocated memory
null
63c648a65f004bf4898cfe6e
2023-02-08T04:03:45.933Z
Question from Code
v1
free dymanically allocated memory using free
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { // 1. struct pixel **pixels = malloc(sizeof(struct pixel *) * height); // 2. for (int i=0; i < height; i++) { pixels[i] = malloc(sizeof(struct pixel) * width); } }
null
null
63c648a65f004bf4898cfe6e
2023-02-08T04:04:50.344Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { // 1. struct pixel **pixels = malloc(sizeof(struct pixel *) * height); // 2. for (int i=0; i < height; i++) { pixels[i] = malloc(sizeof(struct pixel) * width); } }
use free function to free memory
null
63c648a65f004bf4898cfe6e
2023-02-08T18:37:37.456Z
Help Fix Code
v1
null
void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { image = fopen(image, "r");
fix incompatible pointer types passing 'FILE *' (aka 'struct __sFILE *') to parameter of type 'const char *' [-Wincompatible-pointer-types]
null
63c648a65f004bf4898cfe6e
2023-02-08T18:38:15.063Z
Help Fix Code
v1
null
void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { fopen(image, "r");
incompatible pointer types passing 'FILE *' (aka 'struct __sFILE *') to parameter of type 'const char *' [-Wincompatible-pointer-types]
null
63c648a65f004bf4898cfe6e
2023-02-08T18:39:15.743Z
Question from Code
v1
fix incompatible pointer types passing 'FILE *' to parameter of type 'const char *'
void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { image = fopen(image, "r");
null
null
63c648a65f004bf4898cfe6e
2023-02-08T18:39:47.978Z
Question from Code
v1
open image using fopen
void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { image = fopen(image, "r");
null
null
63c648a65f004bf4898cfe6e
2023-02-08T18:40:11.814Z
Help Fix Code
v1
null
void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { image = fopen(image, "r");
open file image using fopen
null
63c648a65f004bf4898cfe6e
2023-02-09T02:41:54.352Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { struct user new_user; strcpy(new_user.name, name);
iterate through list of user structs
null
63c648a65f004bf4898cfe6e
2023-02-09T02:46:40.100Z
Question from Code
v1
iterat through user_ptr_add which is list of user structs
int create_user(const char *name, User **user_ptr_add) { struct user new_user; strcpy(new_user.name, name);
null
null
63c648a65f004bf4898cfe6e
2023-02-09T03:52:51.388Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { struct user new_user; strcpy(new_user.name, name);
iterate through list of user structs, and add new_user to end of list
null
63c648a65f004bf4898cfe6e
2023-02-09T03:53:55.800Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { struct user new_user; strcpy(new_user.name, name); new_user.next = NULL;
how to iterate to end of user_ptr_add and insert new_user at tail of list
null
63c648a65f004bf4898cfe6e
2023-02-09T03:56:22.863Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { struct user new_user; strcpy(new_user.name, name); new_user.next = NULL;
how to iterate to end of user_ptr_add
null
63c648a65f004bf4898cfe6e
2023-02-09T04:04:21.753Z
Help Fix Code
v1
null
void list_users(const User *curr) { while (curr != NULL) { printf("%s\n", curr.name); curr = curr->next; } }
Print the usernames of all users in the list starting at curr. Names should be printed to standard output, one per line.
null
63c648a65f004bf4898cfe6e
2023-02-09T19:51:45.987Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { // 1. struct pixel **pixels = malloc(sizeof(struct pixel *) * height); // 2 - 3 for (int i = 0; i < height; i++) { pixels[i] = malloc(sizeof(struct pixel) * width); while (sizeof(struct pixel) == 3) { fread(&pixels, sizeof(struct pixel), 3, image); } } // 4. return pixels; }
Use the given file and pixel_array_offset to initialize the actual struct pixel values
null
63c648a65f004bf4898cfe6e
2023-02-11T14:59:31.215Z
General Question
v1
get number of elements in a linked list
null
null
null
63c648a65f004bf4898cfe6e
2023-02-12T05:14:23.770Z
Help Fix Code
v1
null
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; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; int update_pic(User *user, const char *filename) { if (strlen(filename) > MAX_NAME) { // +1 bc of null term? return 2; } return -1; }
Change the filename for the profile pic of the given user.
null
63c648a65f004bf4898cfe6e
2023-02-12T05:17:02.608Z
Help Fix Code
v1
null
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; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; int update_pic(User *user, const char *filename) { if (strlen(filename) > MAX_NAME) { // +1 bc of null term? return 2; } strcpy(&user.profile_pic, filename); return -1; }
Change the filename for the profile pic of the given user.
null
63c648a65f004bf4898cfe6e
2023-02-12T05:19:02.723Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct user *friends[MAX_FRIENDS]; struct user *next; } User; int update_pic(User *user, const char *filename) { if (strlen(filename) > MAX_NAME) { return 2; } else if (fopen()) // checks passed, change filename strcpy(user->profile_pic, filename); return 0; }
check for if the file does not exist or cannot be opened
null
63c648a65f004bf4898cfe6e
2023-02-12T05:40:01.954Z
Help Fix Code
v1
null
User *find_user(const char *name, const User *head) { User *user_ptr = head; while (user_ptr->next != NULL || ((User *)user_ptr)->name != name) { user_ptr = user_ptr->next; } if (user_ptr->name == name) { // case where user name exists return user_ptr; } else { return NULL; } }
how to fix error returning 'const User *' (aka 'const struct user *') from a function with result type 'User *' (aka 'struct user *') discards qualifiers
null
63c648a65f004bf4898cfe6e
2023-02-12T05:44:16.108Z
Help Fix Code
v1
null
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; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; void create_user(const char *name, User **user_ptr_add) { }
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.
null
63c648a65f004bf4898cfe6e
2023-02-12T05:46:01.507Z
Question from Code
v1
how to initialize post and friends parameters of new user
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; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; void create_user(const char *name, User **user_ptr_add) { }
null
null
63c648a65f004bf4898cfe6e
2023-02-12T05:50:20.312Z
Help Fix Code
v1
null
void create_user(const char *name, User **user_ptr_add) { // create with given name struct user new_user; strcpy(new_user.name, name); strcpy(new_user.profile_pic, NULL); }
fix compiler error for profile_pic: null argument where non-null required
null
63c648a65f004bf4898cfe6e
2023-02-12T05:52:56.685Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct user *friends[MAX_FRIENDS]; struct user *next; } User; int create_user(const char *name, User **user_ptr_add) { struct user new_user; strcpy(new_user.name, name); strcpy(new_user.profile_pic, ""); // check new_user.friends = NULL; new_user.next = NULL;
how to initialize .friends parameter when there are no friends
null
63c648a65f004bf4898cfe6e
2023-02-12T05:54:33.098Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct user *friends[MAX_FRIENDS]; struct user *next; } User; int create_user(const char *name) { struct user new_user; strcpy(new_user.name, name); strcpy(new_user.profile_pic, ""); // check new_user.friends = NULL; new_user.next = NULL;
initialize new_user.friends to be empty
null
63c648a65f004bf4898cfe6e
2023-02-12T05:58:32.583Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct user *friends[MAX_FRIENDS]; struct user *next; } User; int create_user(const char *name) { struct user new_user; struct user new_user; strcpy(new_user.name, name); new_user->profile_pic = malloc(sizeof(char) * MAX_NAME); // initialize post new_user->friends = malloc(sizeof(struct user)); new_user.next = NULL;
fix "operator -> or ->* applied to "struct user" instead of to a pointer type"
null
63c648a65f004bf4898cfe6e
2023-02-12T06:00:06.371Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct user *friends[MAX_FRIENDS]; struct user *next; } User; int create_user(const char *name) { User new_user; strcpy(new_user.name, name); new_user->profile_pic = malloc(sizeof(char) * MAX_NAME); // initialize post new_user->friends = malloc(sizeof(struct user)); new_user.next = NULL;
fix "operator -> or ->* applied to "struct user" instead of to a pointer type"
null
63c648a65f004bf4898cfe6e
2023-02-12T06:01:18.345Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct user *friends[MAX_FRIENDS]; struct user *next; } User; int create_user(const char *name) { User new_user; strcpy(new_user.name, name); new_user.profile_pic = malloc(sizeof(char) * MAX_NAME); // initialize post new_user.friends = malloc(sizeof(struct user)); new_user.next = NULL;
fix error expression must be a modifiable lvalue
null
63c648a65f004bf4898cfe6e
2023-02-12T06:03:58.759Z
General Question
v1
how to initialize empty array of chars with 10 characters
null
null
null
63c648a65f004bf4898cfe6e
2023-02-12T06:06:45.697Z
Help Fix Code
v1
null
profilepic = char array[10];
initialize array profilepic with 10 chars
null
63c648a65f004bf4898cfe6e
2023-02-12T06:09:02.662Z
General Question
v1
is array[10] a string
null
null
null
63c648a65f004bf4898cfe6e
2023-02-12T22:11:13.466Z
General Question
v1
how to add element to front of linked list
null
null
null
63c648a65f004bf4898cfe6e
2023-02-12T22:20:55.985Z
General Question
v1
how to get first element of linked list
null
null
null
63c648a65f004bf4898cfe6e
2023-02-12T23:09:57.351Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct user *friends[MAX_FRIENDS]; struct user *next; } User; void create_user(const char *name, User **user_ptr_add) { // create temp user struct with given name User new_user; strcpy(new_user.name, name); strcpy(new_user.profile_pic, ""); new_user->friends = NULL; new_user.next = NULL; }
how to initialize friends member to be empty (NULL)
null
63c648a65f004bf4898cfe6e
2023-02-12T23:11:51.906Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct user *friends[MAX_FRIENDS]; struct user *next; } User; void create_user(const char *name, User **user_ptr_add) { // create temp user struct with given name User new_user; strcpy(new_user.name, name); strcpy(new_user.profile_pic, ""); new_user->friends = NULL; new_user.next = NULL; }
how to to set each element of the array of friends pointers to NULL without using memset
null
63c648a65f004bf4898cfe6e
2023-02-12T23:22:59.560Z
Help Fix Code
v1
null
typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post;
how to initialize an empty post struct
null
63c648a65f004bf4898cfe6e
2023-02-12T23:34:15.646Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { // create temp user struct with given name User new_user; strcpy(new_user.name, name); strcpy(new_user.profile_pic, ""); new_user.first_post = NULL; // initialize friends list to be all NULL for (int i = 0; i < MAX_FRIENDS; i++) { new_user.friends[i] = NULL; } new_user.next = NULL; if (strlen(name) > MAX_NAME) { // +1 for null term? return 2; } // success case: list of pointers is empty if (user_ptr_add == NULL) { *user_ptr_add = &new_user; return 0; } // check whether name exists in list of pointers User *head = *user_ptr_add; while (head->next != NULL) { if (head->name == name) { return 1; } head = head->next; } // checks passed; allocate memory for the new user, add, and return // struct user *new_userr = malloc(sizeof(struct user)); new_user = malloc(sizeof(struct user)); head->next = &new_user; return 0; }
how to allocate heap memory for new_user
null
63c648a65f004bf4898cfe6e
2023-02-12T23:36:37.313Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { // create temp user struct with given name User new_user; strcpy(new_user.name, name); strcpy(new_user.profile_pic, ""); new_user.first_post = NULL; // initialize friends list to be all NULL for (int i = 0; i < MAX_FRIENDS; i++) { new_user.friends[i] = NULL; } new_user.next = NULL; if (strlen(name) > MAX_NAME) { // +1 for null term? return 2; } // success case: list of pointers is empty if (user_ptr_add == NULL) { *user_ptr_add = &new_user; return 0; } // check whether name exists in list of pointers User *head = *user_ptr_add; while (head->next != NULL) { if (head->name == name) { return 1; } head = head->next; } // checks passed; allocate memory for the new user, add, and return // struct user *new_userr = malloc(sizeof(struct user)); new_user = malloc(sizeof(struct user)); head->next = &new_user; return 0; }
how to use malloc on new_user
null
63c648a65f004bf4898cfe6e
2023-02-12T23:37:17.951Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { // create temp user struct with given name User new_user; strcpy(new_user.name, name); strcpy(new_user.profile_pic, ""); new_user.first_post = NULL; // initialize friends list to be all NULL for (int i = 0; i < MAX_FRIENDS; i++) { new_user.friends[i] = NULL; } new_user.next = NULL; if (strlen(name) > MAX_NAME) { // +1 for null term? return 2; } // success case: list of pointers is empty if (user_ptr_add == NULL) { *user_ptr_add = &new_user; return 0; } // check whether name exists in list of pointers User *head = *user_ptr_add; while (head->next != NULL) { if (head->name == name) { return 1; } head = head->next; } // checks passed; allocate memory for the new user, add, and return // struct user *new_userr = malloc(sizeof(struct user)); new_user = malloc(sizeof(struct user)); head->next = &new_user; return 0; }
how to use malloc to dynamically allocate space for new_user
null
63c648a65f004bf4898cfe6e
2023-02-13T00:39:23.950Z
Help Fix Code
v1
null
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 create_user(const char *name, User **user_ptr_add) { // create temp user struct with given name User *new_user; strcpy(&new_user.name, name); strcpy(&new_user.profile_pic, ""); &new_user.first_post = NULL; // initialize friends list to be all NULL for (int i = 0; i < MAX_FRIENDS; i++) { &new_user.friends[i] = NULL; } &new_user.next = NULL;
intialize new user with the given name
null
63c648a65f004bf4898cfe6e
2023-02-13T00:41:57.842Z
Help Fix Code
v1
null
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 create_user(const char *name, User **user_ptr_add) { // create temp user struct with given name User *new_user; strcpy(&new_user.name, name); strcpy(&new_user.profile_pic, ""); &new_user.first_post = NULL; // initialize friends list to be all NULL for (int i = 0; i < MAX_FRIENDS; i++) { &new_user.friends[i] = NULL; } &new_user.next = NULL;
how to deference new_user to just a struct user
null
63c648a65f004bf4898cfe6e
2023-02-13T03:35:19.307Z
Help Fix Code
v1
null
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 make_friends(const char *name1, const char *name2, User *head) { // check if either user exists in list if (find_user(name1, head) || find_user(name2, head) == NULL) { return 4; } // check whether names entered are the same else if (strcmp(name1, name2) == 0) { return 3; } // since we know past this point that both users exist User *user1 = (User *)find_user(name1, head); // incompatible pointer type - friends is struct user *[10] User *friends1 = user1->friends; int count1 = 0; while (friends1 != NULL) { count1++; friends1 = friends1->next; } User *user2 = (User *)find_user(name2, head); User *friends2 = user2->friends; int count2 = 0; while (friends2 != NULL) { count2++; friends2 = friends2->next; } // check whether one already has 10 friends if (count1 == 10 || count2 == 10) { return 2; } // check whether already friends: only need to check one user because mutual relationship else if (find_user(name2, friends1) != NULL) { return 1; } // checks passed, add user to each others 'friends' members (both ways) else { // adding user2 as a friend of user1 while (friends1 != NULL) { friends1 = friends1->next; } friends1->next = user2; // adding user1 as a friend of user2 while (friends2 != NULL) { friends2 = friends2->next; } friends2->next = user1; return 0; } }
how to fix warning: incompatible pointer types initializing 'User *' (aka 'struct user *') with an expression of type 'struct user *[10
null
63c648a65f004bf4898cfe6e
2023-02-13T17:57:58.358Z
Help Fix Code
v1
null
// profile pic FILE *pfp = fopen(user->profile_pic, "r"); // if (pfp != NULL) { fgets(, 100, pfp); }
how to user fgets to print out pfp
null
63c648a65f004bf4898cfe6e
2023-02-13T19:20:04.318Z
Help Fix Code
v1
null
// profile pic FILE *pfp = fopen(user->profile_pic, "r"); // if (pfp != NULL) { fgets(, 100, pfp); }
what is the buffer for fgets
null
63c648a65f004bf4898cfe6e
2023-02-13T19:20:30.636Z
Help Fix Code
v1
null
// profile pic FILE *pfp = fopen(user->profile_pic, "r"); // if (pfp != NULL) { fgets(, 100, pfp); }
how to allocate buffer for fgets
null
63c648a65f004bf4898cfe6e
2023-02-13T19:35:21.096Z
Help Fix Code
v1
null
// profile pic FILE *pfp = fopen(user->profile_pic, "r"); // if (pfp != NULL) { fgets(, 100, pfp); }
how to print the contents of the file row by row
null
63c648a65f004bf4898cfe6e
2023-02-13T19:40:05.789Z
General Question
v1
loop through each row of a file
null
null
null
63c648a65f004bf4898cfe6e
2023-02-13T19:48:44.987Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct user *friends[MAX_FRIENDS]; struct user *next; } User; int print_user(const User *user) { if (user == NULL) { return 1; } FILE *pfp = fopen(user->profile_pic, "r"); char row[100]; while () { fgets(row[i], 100, pfp); } fclose(pfp);
loop through and print each row of the file pfp
null
63c648a65f004bf4898cfe6e
2023-02-14T15:57:42.097Z
Help Fix Code
v1
null
typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; void make_post(const User *author, User *target, char *contents) { // either one or author or target names does not exist if (author == NULL || target == NULL) { return 2; } /* So the flow goes like this (in make_post): 1) check if user is null 2) have a for loop that iterates until MAX_FRIENDS 3) inside the for loop, make a check to see if the author and target are friends 4) IF they are friends, initialize the time_t curr_time and allocate space for the ENTIRE new post with MALLOC 5) then assign the values for all the members of this struct (do the contents, time, next and author) and then make sure this post is the FIRST POST (linked list stuff you know) */ // loop through one user's friends int friends = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (author->friends[i] == target) { friends = 1; } } // users not friends, early return if (friends == 0) { return 1; } // checks passed, initialize a new post Post *new_post = malloc(sizeof(struct post)); // malloc error check if (new_post == NULL) { exit(1); } strcpy(new_post->author, author->name); strcpy(new_post->contents, contents); time_t *curr_time; new_post->date = curr_time; // &curr_time? new_post->next = NULL; // 'send' post to target; pointer at head, takes care of both whether empty or not cases new_post->next = target->first_post; return 0; }
how to fix warning: variable 'curr_time' is uninitialized when used here [-Wuninitialized] new_post->date = curr_time;
null
63c648a65f004bf4898cfe6e
2023-02-14T15:58:41.431Z
Help Fix Code
v1
null
typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; void make_post(const User *author, User *target, char *contents) { // either one or author or target names does not exist if (author == NULL || target == NULL) { return 2; } /* So the flow goes like this (in make_post): 1) check if user is null 2) have a for loop that iterates until MAX_FRIENDS 3) inside the for loop, make a check to see if the author and target are friends 4) IF they are friends, initialize the time_t curr_time and allocate space for the ENTIRE new post with MALLOC 5) then assign the values for all the members of this struct (do the contents, time, next and author) and then make sure this post is the FIRST POST (linked list stuff you know) */ // loop through one user's friends int friends = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (author->friends[i] == target) { friends = 1; } } // users not friends, early return if (friends == 0) { return 1; } // checks passed, initialize a new post Post *new_post = malloc(sizeof(struct post)); // malloc error check if (new_post == NULL) { exit(1); } strcpy(new_post->author, author->name); strcpy(new_post->contents, contents); time_t *curr_time; new_post->date = curr_time; // &curr_time? new_post->next = NULL; // 'send' post to target; pointer at head, takes care of both whether empty or not cases new_post->next = target->first_post; return 0; }
how to fix warning: incompatible integer to pointer conversion initializing 'time_t *' (aka 'long *') with an expression of type 'time_t' (aka 'long') [-Wint-conversion] time_t *curr_time = time(NULL);
null
63c648a65f004bf4898cfe6e
2023-02-14T16:07:22.595Z
Help Fix Code
v1
null
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; /* * From the list pointed to by *user_ptr_del, delete the user * with the given name. * Remove the deleted user from any lists of friends. * * Return: * - 0 on success. * - 1 if a user with this name does not exist. */ int delete_user(const char *name, User **user_ptr_del) { if (find_user(name, user_ptr_del) == NULL) { // don't think this is right help return 1; }
how to fix warning: incompatible pointer types passing 'User **' (aka 'struct user **') to parameter of type 'const User *' (aka 'const struct user *'); dereference with * [-Wincompatible-pointer-types] if (find_user(name, user_ptr_del) == NULL) {
null
63c648a65f004bf4898cfe6e
2023-02-14T21:32:11.371Z
General Question
v1
how to delete first element of linked list using prev and curr
null
null
null
63c648a65f004bf4898cfe6e
2023-02-14T21:44:13.643Z
Help Fix Code
v1
null
/* * From the list pointed to by *user_ptr_del, delete the user * with the given name. * Remove the deleted user from any lists of friends. * * Return: * - 0 on success. * - 1 if a user with this name does not exist. */ int delete_user(const char *name, User **user_ptr_del) { if (find_user(name, *user_ptr_del) == NULL) { // don't think this is right help return 1; } // user_ptr_del is a pointer to a user pointer // at the point, user exists User *prev = *user_ptr_del; User *curr = prev->next; // special case, when there is only one element if (curr = NULL) { free(prev->first_post); // need to loop prev = NULL; free(prev); } while (curr != NULL) { // deleting head of list if (prev->name == name) { prev->next = NULL; free(prev->first_post); // need to loop free(prev); } if (curr->name != name) { prev->next = curr; curr = curr->next; }
delete user with given name using prev and curr
null
63c648a65f004bf4898cfe6e
2023-02-15T07:28:04.400Z
Help Fix Code
v1
null
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; /* * Print a user profile. * For an example of the required output format, see the example output * linked from the handout. * Return: * - 0 on success. * - 1 if the user is NULL. */ int print_user(const User *user) { if (user == NULL) { printf("user dne\n"); return 1; } // friends printf("Friends: \n"); for (int i = 0; i < MAX_FRIENDS; i++) { if (user->friends[i] != NULL) { printf("%s\n", user->friends[i]->name); } } printf("------------------------------------------\n");
how to print out all non-NULL elements of friends[MAX_FRIENDS]
null
63c648a65f004bf4898cfe6e
2023-02-15T15:01:39.852Z
Help Fix Code
v1
null
typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; int make_post(const User *author, User *target, char *contents) { // either one or author or target names does not exist if (author == NULL || target == NULL) { return 2; } // loop through one user's friends int friends = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (author->friends[i] == target) { friends = 1; } } // users not friends, early return if (friends == 0) { return 1; } // checks passed, initialize a new post Post *new_post = malloc(sizeof(struct post)); // malloc error check if (new_post == NULL) { exit(1); } strcpy(new_post->author, author->name); strcpy(new_post->contents, contents); time_t *curr_time = malloc(sizeof(time_t)); new_post->date = curr_time; new_post->next = NULL; // 'send' post to target; pointer at head, takes care of both whether empty or not cases new_post->next = target->first_post; return 0; }
how to get rid of segmentation faults at line 33: strcpy(new_post->contents, contents);
null
63c648a65f004bf4898cfe6e
2023-02-15T16:06:10.089Z
Help Fix Code
v1
null
typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; int make_post(const User *author, User *target, char *contents) { // either one or author or target names does not exist if (author == NULL || target == NULL) { return 2; } // loop through one user's friends int friends = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (author->friends[i] == target) { friends = 1; } } // users not friends, early return if (friends == 0) { return 1; } // checks passed, initialize a new post Post *new_post = malloc(sizeof(struct post)); // malloc error check if (new_post == NULL) { exit(1); } strcpy(new_post->author, author->name); strcpy(new_post->contents, contents); time_t *curr_time = malloc(sizeof(time_t)); new_post->date = curr_time; new_post->next = NULL; // 'send' post to target; pointer at head, takes care of both whether empty or not cases new_post->next = target->first_post; return 0; }
how to get rid of error: "invalid write of size 1" in line 33
null
63c648a65f004bf4898cfe6e
2023-02-15T17:48:24.259Z
Help Fix Code
v1
null
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 delete_user(const char *name, User **user_ptr_del) { if (find_user(name, *user_ptr_del) == NULL) { return 1; } // at the point, confirmed that the user exists User *user_del = find_user(name, *user_ptr_del); // Post *user_posts = user_del->first_post; // only loop if there are posts if (user_del->first_post != NULL) { // user_del has posts, can loop and free now Post *user_posts = user_del->first_post; while (user_posts->next != NULL) { // need to store copy of rest of list // or else unable to access after freeing Post *temp = user_posts->next; free(user_posts->date); free(user_posts->contents); free(user_posts); user_del->first_post = temp; // off!! }
how to fix segmentation error
null
63c648a65f004bf4898cfe6e
2023-02-22T23:01:31.060Z
Help Fix Code
v1
null
int element; /*assigned a hidden value */ /* In the following line, write what <cond> should be in: "switch(<cond>){" */ switch (element) { /* The body of the switch statement goes here. The first case is written for you below. */ case 1 : printf("earth"); break; /* Write case 2 (water) here. */ case 2 : printf("water"); break; /* Write case 3 (air) here. */ case 3 : printf("air"); break; /* Write case 4 (fire) here. */ case 4 : printf("fire"); break; /* Write the default case here. */ default : printf("not a valid elements"); return 0; }
An integer variable, element is initialized as a hidden value. Write a switch statement with cases 1-4 that prints one of the four classical elements based on the hidden integer value. Write the cases in the following order (beginning with case 1): earth, water, air, and fire. The default case should print "not a valid element".
null
63c648a65f004bf4898cfe6e
2023-02-22T23:02:02.487Z
Help Fix Code
v1
null
int element; /*assigned a hidden value */ /* In the following line, write what <cond> should be in: "switch(<cond>){" */ switch (element) { /* The body of the switch statement goes here. The first case is written for you below. */ case 1 : printf("earth"); break; /* Write case 2 (water) here. */ case 2 : printf("water"); break; /* Write case 3 (air) here. */ case 3 : printf("air"); break; /* Write case 4 (fire) here. */ case 4 : printf("fire"); break; /* Write the default case here. */ default : printf("not a valid elements"); }
An integer variable, element is initialized as a hidden value. Write a switch statement with cases 1-4 that prints one of the four classical elements based on the hidden integer value. Write the cases in the following order (beginning with case 1): earth, water, air, and fire. The default case should print "not a valid element".
null
63c648a65f004bf4898cfe6e
2023-02-22T23:02:58.596Z
Help Fix Code
v1
null
int element; /*assigned a hidden value */ /* In the following line, write what <cond> should be in: "switch(<cond>){" */ switch (element) { /* The body of the switch statement goes here. The first case is written for you below. */ case 1 : printf("earth"); break; /* Write case 2 (water) here. */ case 2 : printf("water"); break; /* Write case 3 (air) here. */ case 3 : printf("air"); break; /* Write case 4 (fire) here. */ case 4 : printf("fire"); break; /* Write the default case here. */ default : printf("not a valid elements"); }
fix error: Compilation error: In function 'main': 3:1: error: expected expression before 'switch' 10 | switch (element) { | ^~~~~~
null
63c648a65f004bf4898cfe6e
2023-02-22T23:09:37.508Z
Help Fix Code
v1
null
int element; /*assigned a hidden value */ /* In the following line, write what <cond> should be in: "switch(<cond>){" */ switch (element) {
An integer variable, element is initialized as a hidden value. Write a switch statement with cases 1-4 that prints one of the four classical elements based on the hidden integer value. Write the cases in the following order (beginning with case 1): earth, water, air, and fire. The default case should print "not a valid element".
null
63c648a65f004bf4898cfe6e
2023-02-22T23:14:05.526Z
Help Fix Code
v1
null
int element; /*assigned a hidden value */ /* In the following line, write what <cond> should be in: "switch(<cond>){" */ switch (element) {
fix error: 3:8: error: expected ')' before 'switch' 10 | element switch(element) { | ^~~~~~~ | ) 9:11: note: to match this '(' 9 | switch( | ^ Please check the exercise description. There's an issue in your code: expected expression before '}' token
null
63c648a65f004bf4898cfe6e
2023-02-22T23:16:08.783Z
Help Fix Code
v1
null
int element; /*assigned a hidden value */ /* In the following line, write what <cond> should be in: "switch(<cond>){" */ switch (element) {
Compilation error: In function 'main': 3:1: error: expected expression before 'switch' 10 | switch (element) { | ^~~~~~ Please check the exercise description. There's an issue in your code: expected expression before '}' token1:5: warning: variable 'element' set but not used [-Wunused-but-set-variable] 6 | int element; /*assigned a hidden value */ | ^~~~~~~
null
63c648a65f004bf4898cfe6e
2023-02-22T23:17:35.287Z
Help Fix Code
v1
null
int element; /*assigned a hidden value */ /* In the following line, write what <cond> should be in: "switch(<cond>){" */ switch (element) {
how to initialize element in switch statement
null
63c648a65f004bf4898cfe6e
2023-02-22T23:18:06.994Z
Help Fix Code
v1
null
int element; /*assigned a hidden value */ /* In the following line, write what <cond> should be in: "switch(<cond>){" */ switch (element) {
what does /* In the following line, write what <cond> should be in: "switch(<cond>){" */ mean
null
63c648a65f004bf4898cfe6e
2023-02-22T23:28:59.011Z
Help Fix Code
v1
null
int var_a, var_b, var_c; if (var_a == var_b && var_a == var_c && var_b == var_c) { printf("none unique"); } else if (var_a != var_b && var_a != var_b && var_b != var_c) { printf("all unique"); } else { printf("some unique"); }
why does is this not completely correct
null
63c648a65f004bf4898cfe6e
2023-02-23T00:13:48.163Z
Help Fix Code
v1
null
int main() { int start = 3; int repeat = 4; for (int i = 0; i <= repeat; i++) { for (int j = start; j>=1; j--) { printf("%d ", j, "blastoff"); } printf("\n"); } }
Below you have a program fragment where the integer variables start and repeat have been assigned values in code that is hidden. Your task is to write a nested loop to print lines of integers counting backwards from start to 1 and then print Blastoff. You should do this repeat times. For example, if start is 3 and repeat is 4, your loop should print 3 2 1 Blastoff 3 2 1 Blastoff 3 2 1 Blastoff 3 2 1 Blastoff
null
63c648a65f004bf4898cfe6e
2023-02-23T00:26:02.907Z
Help Fix Code
v1
null
#include <stdio.h> int main() { int start = 5; // you don't have to use all these variables but you may want them int stop = 10; int i; do { printf("%d", i); i ++; } int i = start; while (i < stop); return 0; }
Complete the program below so that it prints the squares of the integers from 5 to 9 inclusive. Use a do while loop.
null
63c648a65f004bf4898cfe6e
2023-02-23T00:26:35.310Z
Help Fix Code
v1
null
#include <stdio.h> int main() { int start = 5; // you don't have to use all these variables but you may want them int stop = 10; int i; do { printf("%d", i); i ++; } while (i < stop); return 0; }
Complete the program below so that it prints the squares of the integers from 5 to 9 inclusive. Use a do while loop.
null
63c648a65f004bf4898cfe6e
2023-02-23T00:27:49.616Z
Help Fix Code
v1
null
#include <stdio.h> int main() { int start = 5; // you don't have to use all these variables but you may want them int stop = 10; int i; do { i = start; printf("%d", i * i); i ++; } while (i < stop); return 0; }
Complete the program below so that it prints the squares of the integers from 5 to 9 inclusive. Use a do while loop.
null
63c648a65f004bf4898cfe6e
2023-02-23T00:28:25.244Z
Help Fix Code
v1
null
#include <stdio.h> int main() { int start = 5; // you don't have to use all these variables but you may want them int stop = 10; int i; do { i = start; printf("%d", i * i); i ++; } while (i < stop); return 0; }
fix runtime error
null
63c648a65f004bf4898cfe6e
2023-02-28T04:54:58.064Z
Question from Code
v1
what does the if (saw_null) condition mean
int terminate_string(char *c, int index) { int saw_null = 0; for (int i = 0; i < index; i++) { if (saw_null) { c[i] = '\0'; } } }
null
null
63c648a65f004bf4898cfe6e
2023-02-28T04:55:52.108Z
Question from Code
v1
what does if condition mean
int terminate_string(char *c, int index) { int saw_null = 0; for (int i = 0; i < index; i++) { if (0) { c[i] = '\0'; } } }
null
null
63c648a65f004bf4898cfe6e
2023-02-28T04:56:50.975Z
Explain Code
v1
null
int terminate_string(char *c, int index) { int saw_null = 0; for (int i = 0; i < index; i++) { if (saw_null) { c[i] = '\0'; } else { if (c[i] == '\0') { saw_null = i; } } } }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T01:16:03.158Z
Question from Code
v2
What does the program print to stderr when it runs without interruption?
int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); x += 2; fprintf(stderr, "outside %d", x); return 0; }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T01:17:50.174Z
Question from Code
v2
What does the program print to stderr if the user presses Ctrl+C at the moment when the program is at position A?
int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); x += 2; fprintf(stderr, "outside %d", x); return 0; }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T01:25:29.404Z
Question from Code
v2
What does the program print to stderr if the user presses Ctrl+C at the moment when the program is at position B?
int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); x += 2; fprintf(stderr, "outside %d", x); return 0; }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T07:24:02.766Z
General Question
v2
how to use strtok to parse through a makefile
null
null
null
63c648a65f004bf4898cfe6e
2023-03-13T07:26:52.792Z
Question from Code
v2
how to iterate through each line of a makefile
#This is a test makefile for A3.It uses the files from the early version #of the demo that we did in week 6. main : linked_list.o main.o gcc - Wall - g - std = gnu99 - o main linked_list.o main .o main.o : main.c linked_list.h gcc - Wall - g - std = gnu99 - c main .c linked_list.o : linked_list.c linked_list.h gcc - Wall - g - std = gnu99 - c linked_list.c #notice that this target has no dependencies clean : rm - f main rm - f linked_list.o rm - f main.o
null
null
63c648a65f004bf4898cfe6e
2023-03-13T07:31:25.544Z
Question from Code
v2
how to traverse to line 5 in this makefile
#This is a test makefile for A3.It uses the files from the early version #of the demo that we did in week 6. main : linked_list.o main.o gcc - Wall - g - std = gnu99 - o main linked_list.o main .o main.o : main.c linked_list.h gcc - Wall - g - std = gnu99 - c main .c linked_list.o : linked_list.c linked_list.h gcc - Wall - g - std = gnu99 - c linked_list.c #notice that this target has no dependencies clean : rm - f main rm - f linked_list.o rm - f main.o
null
null
63c648a65f004bf4898cfe6e
2023-03-13T18:56:42.335Z
Help Fix Code
v2
how to not print the colon :
#include <stdio.h> #include <string.h> int main () { char str[256] = "main : linked_list.o main.o "; const char s[2] = " "; char *token; /* get the first token */ token = strtok(str, s); /* walk through other tokens */ while( token != NULL ) { printf( " %s\n", token ); token = strtok(NULL, s); } return(0); }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T18:59:07.357Z
Help Fix Code
v2
: is still printing
#include <stdio.h> #include <string.h> int main () { char str[256] = "main : linked_list.o main.o "; const char s[2] = " "; char *token; /* get the first token */ token = strtok(str, s); /* walk through other tokens */ while( token != NULL ) { if (token != ":") { printf( " %s\n", token ); } token = strtok(NULL, s); } return(0); }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T19:04:23.010Z
Help Fix Code
v2
line 17 to only print the space-separated strings after the colon :
#include <stdio.h> #include <string.h> int main () { char str[256] = "main : linked_list.o main.o "; const char s[2] = " "; char *token; /* get the first token */ token = strtok(str, s); char *target = token; printf("the target is %s", target); /* walk through other tokens */ while( token != NULL ) { if (strcmp(token, ":") != 0) { printf( "Its dependencies are %s\n", token ); } token = strtok(NULL, s); } return(0); }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T19:06:29.637Z
Help Fix Code
v2
how to skip the token if it is a colon : and get the next token
#include <stdio.h> #include <string.h> int main () { char str[256] = "main : linked_list.o main.o "; const char s[2] = " "; char *token; /* get the first token */ token = strtok(str, s); char *target = token; printf("the target is %s", target); /* walk through other tokens */ while( token != NULL ) { if (strcmp(token, ":") != 0) { printf( "Its dependencies are %s\n", token ); } token = strtok(NULL, s); } return(0); }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T19:11:12.813Z
Help Fix Code
v2
i want output to be: the target is main Its dependencies are linked_list.o Its dependencies are linked_list.o
#include <stdio.h> #include <string.h> int main () { char str[256] = "main : linked_list.o main.o "; const char s[2] = " "; char *token; /* get the first token */ token = strtok(str, s); char *target = token; printf("the target is %s\n", target); /* walk through other tokens */ while( token != NULL ) { if (strcmp(token, ":") == 0) { token = strtok(NULL, s); } if (strcmp(token, ":") != 0) { printf( "Its dependencies are %s\n", token ); token = strtok(NULL, s); } } return(0); }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T19:14:22.802Z
Help Fix Code
v2
i want output to be: the target is main Its dependencies are linked_list.o Its dependencies are linked_list.o
#include <stdio.h> #include <string.h> int main () { char str[256] = "main : linked_list.o main.o "; const char s[2] = " "; char *token; /* get the first token */ token = strtok(str, s); char *target = token; printf("the target is %s\n", target); /* walk through other tokens */ while( token != NULL ) { if (strcmp(token, ":") == 0) { token = strtok(NULL, s); } if (strcmp(token, ":") != 0) { printf( "Its dependencies are %s\n", token ); token = strtok(NULL, s); } } return 0; }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T19:42:36.490Z
Help Fix Code
v2
save all token pointers into an array of dependency struct pointers
while (fgets(line, fp) != 0) { char *target = strtok(line, delim); token = strtok(NULL, delim); // start at token after target int num_dependencies; // keep track of # deps -> initialize list of dep pointers // initializer list of dep pointers while (token != NULL) { if (strcmp(token, ":") == 0) { // skip over the colon ':' token = strtok(NULL, delim); } // the remaining tokens are all dependencies // all dependencies are also rules, so initialize each as a rule_node struct Rule *new_rule_dep; strncpy(new_rule_dep->target, token, MAXLINE); // initialize dependency as new_dep Dependency *new_dep; new_dep->rule = new_rule_dep; token = strtok(NULL, delim); num_dependencies++; } file_line_number++; // move on to next line in the file }
null
null
63c648a65f004bf4898cfe6e
2023-03-13T20:49:19.511Z
Question from Code
v2
how to skip lines with comments and white space of a makefile to get to line 5
main : linked_list.o main.o gcc - Wall - g - std = gnu99 - o main linked_list.o main .o main.o : main.c linked_list.h gcc - Wall - g - std = gnu99 - c main .c linked_list.o : linked_list.c linked_list.h gcc - Wall - g - std = gnu99 - c linked_list.c #notice that this target has no dependencies clean : rm - f main rm - f linked_list.o rm - f main.o
null
null
63c648a65f004bf4898cfe6e
2023-03-13T21:23:35.908Z
Help Fix Code
v2
line 14: error: array initializer must be an initializer list or string literal
/* Read from the open file fp, and create the linked data structure that represents the Makefile contained in the file. See the top of pmake.h for the specification of Makefile contents. */ Rule *parse_file(FILE *fp) { // setting up to read through the makefile char line[MAXLINE]; const char delim[2] = ' '; // delimiter for strtok char *token; int file_line_number = 0; Rule first_rule; // this is the one that is being returned while (fgets(line, MAXLINE, fp) != 0) { // until the end of the file // another while loop to check if the first character of the line is alphanumeric // if so, that is a new rule, // initialize a new rule Rule *new_rule; char *target = strtok(line, delim); strncpy(new_rule->target, target, MAXLINE); new_rule->dependencies = NULL; new_rule->actions = NULL; new_rule->next_rule = NULL;
null
null
63c648a65f004bf4898cfe6e
2023-03-13T22:48:23.190Z
Help Fix Code
v2
where is the missing semicolon
// go through all dependencies while (token != NULL) { if (strchr(token, ':') != NULL) { continue; } else { Rule *rule_dep; Dependency *new_dep; // initialize } token = strtok(NULL, delimiter); // go to next token }
null
null
63c648a65f004bf4898cfe6e
2023-03-14T04:18:45.730Z
Help Fix Code
v2
getting warning: implicit declaration of function ‘find_rule’
Rule *parse_file(FILE *fp) { // initializing char line[MAXLINE]; Rule *first_rule; first_rule = malloc(sizeof(Rule)); if (first_rule == NULL) { perror("malloc"); exit(1); } // iterating through the entire makefile while (fgets(line, MAXLINE, fp) != NULL) { if (is_comment_or_empty(line) == 1) { // line starts with '#' or ' ' continue; } // it starts getting serious here else { // initializing global variables that are used in both branches Rule *curr_rule; curr_rule = malloc(sizeof(Rule)); if (curr_rule == NULL) { perror("malloc"); exit(1); } const char delimiter = ' '; // tokenize target char *target; target = strtok(line, &delimiter); // want to initialize target and dependencies before actions if (line[0] != '\t') { // rule struct has not been added to first_rule if (find_rule(first_rule, target) == NULL) { // curr_rule = malloc(sizeof(Rule)); // if (curr_rule == NULL) { // perror("malloc"); // exit(1); // } strncpy(curr_rule->target, target, MAXLINE); insert_rule(first_rule, curr_rule); } Rule *find_rule(Rule *first_rule, char *target) { while (first_rule->next_rule != NULL) { if (strcmp(first_rule->target, target) == 0) { return first_rule; } } return NULL;
null
null
63c648a65f004bf4898cfe6e
2023-03-14T18:19:13.735Z
Help Fix Code
v2
why is this giving me an error. i want to be iterating through the list of rules with first_rule as the head, ad returning whether the struct associated with the target is found
typedef struct rule_node { char *target; Dependency *dependencies; Action *actions; struct rule_node *next_rule; } Rule; Rule *find_rule(Rule *first_rule, char *target) { while (first_rule->next_rule != NULL) { // TODO: conditional jump / var here ? if (strcmp(first_rule->target, target) == 0) { return first_rule; } first_rule = first_rule->next_rule; } return NULL;
null
null