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
63c6489e5f004bf4898cfe23
2023-03-16T17:03:06.424Z
Help Fix Code
v2
How do you get rid of the issue with curr_rule pointing to the next rule?
Rule *parse_file(FILE *fp) { // Look through file char a_line[MAXLINE]; // Initalize rules Rule *head_rule = malloc(sizeof(Rule)); Rule *curr_rule = malloc(sizeof(Rule)); while (fgets(a_line, MAXLINE, fp) != NULL) { // Filter out comments and blank lines char *token; token = strtok(a_line, "\r"); if (is_comment_or_empty(token) == 0) { // Each token represents a line in the makefile! while(token != NULL) { // We are on target line and not on an empty line if (token[0] != '\t' && token[0] != '\n') { // printf("%s\n", token); // Get target char *sub_token; sub_token = strtok(token, " "); // It gets words before " " if (strcmp(token, ":") != 0) { // We will grab just the names of the targets in the Makefile // printf("%s", sub_token); curr_rule->target = malloc(sizeof(char) * (strlen(sub_token) + 1)); // + 1 for \0 strncpy(curr_rule->target, sub_token, strlen(sub_token)); } } // Go to the next rule (should move this to action like or have like anothe condition // after checking for target line and action line to check if you have an empty space or something // inside of the while loop of course) if (head_rule == NULL) { // This means we are looking at the first rule head_rule = curr_rule; free(curr_rule); curr_rule = curr_rule->next_rule; } else { curr_rule = curr_rule->next_rule; } token = strtok(NULL, " "); // Go to the next line a.k.a token! } } }
null
null
63c6489e5f004bf4898cfe23
2023-03-16T17:04:39.904Z
Help Fix Code
v2
How do you get rid of the issue with curr_rule pointing to the next rule that is causing a segmentation fault?
Rule *parse_file(FILE *fp) { // Look through file char a_line[MAXLINE]; // Initalize rules Rule *head_rule = malloc(sizeof(Rule)); Rule *curr_rule = head_rule; while (fgets(a_line, MAXLINE, fp) != NULL) { // Filter out comments and blank lines char *token; token = strtok(a_line, "\r"); if (is_comment_or_empty(token) == 0) { // Each token represents a line in the makefile! while(token != NULL) { // We are on target line and not on an empty line if (token[0] != '\t' && token[0] != '\n') { // printf("%s\n", token); // Get target char *sub_token; sub_token = strtok(token, " "); // It gets words before " " if (strcmp(token, ":") != 0) { // We will grab just the names of the targets in the Makefile // printf("%s", sub_token); curr_rule->target = malloc(sizeof(char) * (strlen(sub_token) + 1)); // + 1 for \0 strncpy(curr_rule->target, sub_token, strlen(sub_token)); } } // Go to the next rule (should move this to action like or have like anothe condition // after checking for target line and action line to check if you have an empty space or something // inside of the while loop of course) if (head_rule == NULL) { // This means we are looking at the first rule head_rule = curr_rule; free(curr_rule); curr_rule = curr_rule->next_rule; } else { curr_rule = curr_rule->next_rule; } token = strtok(NULL, " "); // Go to the next line a.k.a token! } } } return head_rule; }
null
null
63c6489e5f004bf4898cfe23
2023-03-17T02:53:52.148Z
Help Write Code
v2
null
null
null
/* Write 100 integers (in binary) to a file with the name given by the command-line * argument. You can write them from 0 to 99 or use random to write random numbers. * This program creates a data file for use by the time_reads program. */ int main(int argc, char **argv) {
63c6489e5f004bf4898cfe23
2023-03-17T03:32:36.061Z
Help Write Code
v2
null
null
null
In an infinite loop, read an int from a random location in the file, and print it to stderr.
63c6489e5f004bf4898cfe23
2023-03-17T04:03:36.148Z
Help Write Code
v2
null
null
null
Now, use sigaction to add a signal handler to your program. Start with something simple that just prints a message to standard out and exits (with termination code 0) when it receives a SIGPROF. Then, to test it, run your program and use kill to send it a SIGPROF signal from the shell in another terminal window. It is important that your signal handler print to stdout for testing.
63c6489e5f004bf4898cfe23
2023-03-17T05:54:36.501Z
Help Fix Code
v2
Get rid of the segmentation fault error.
/* The first command-line argument is the number of seconds to set a timer to run. * The second argument is the name of a binary file containing 100 ints. * Assume both of these arguments are correct. */ int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "Usage: time_reads s filename\n"); exit(1); } seconds = strtol(argv[1], NULL, 10); FILE *fp; if ((fp = fopen(argv[2], "r")) == NULL) { perror("fopen"); exit(1); } /* In an infinite loop, read an int from a random location in the file, * and print it to stderr. */ for (;;) { // get a random number between 0 and the size of the file: fseek(fp, 0, SEEK_END); // get current position of the file pointer int curr_pos = ftell(fp); // get random location int random_location = random() % curr_pos; fseek(fp, random_location, SEEK_SET); // read from random location int *random_int = 0; fread(random_int, sizeof(int), 1, fp); fprintf(stderr, "%d\n", *random_int); } return 1; // something is wrong if we ever get here! }
null
null
63c6489e5f004bf4898cfe23
2023-03-17T06:01:06.283Z
Help Write Code
v2
null
null
null
In an infinite loop, read an int from a random location in the file, and print it to stderr.
63c6489e5f004bf4898cfe23
2023-03-17T06:21:21.431Z
Help Write Code
v2
null
null
null
Add code to set up a timer (using setitimerLinks to an external site.) for s seconds (where s is obtained from the command line). You shouldn't use real time, since your results will be affected if your system is busy. Instead, use ITIMER_PROF to make the itimer send a SIGPROF.
63c6489e5f004bf4898cfe23
2023-03-17T18:04:56.160Z
Help Fix Code
v2
How to get rid of segmentation fault?
int found = 0; Dependency *current = curr_dep; if (head_rule->dependencies != NULL) { while (current != NULL) { Rule *current_rule = current->rule; while (current_rule != NULL) { if (strcmp(current->rule->target, sub_token) == 0) { found += 1; break; } current_rule = current_rule->next_rule; } current = current->next_dep; } }
null
null
63c6489e5f004bf4898cfe23
2023-03-18T05:21:44.163Z
Help Write Code
v2
null
null
null
How do you use this struct to put items in it? typedef struct action_node { char **args; // An array of strings suitable to be passed to execvp struct action_node *next_act; } Action;
63c6489e5f004bf4898cfe23
2023-03-18T08:50:46.077Z
Help Fix Code
v2
Connect the linked list
char *sub_token; sub_token = strtok(token, " \t"); // gets rid of the tab so we can only tokenize just the words curr_action = curr_rule->actions; num = 0; // Count number of sub_tokens there are and store the sub tokens in a temporary array. while (sub_token != NULL) { // printf("%s\n", sub_token); temp_array[num] = malloc(sizeof(char) * (strlen(sub_token) + 1)); if (temp_array[num] == NULL) { perror("malloc"); exit(1); } strcpy(temp_array[num], sub_token); num += 1; sub_token = strtok(NULL, " "); } if (sub_token == NULL) { // Initalize curr_action and args and then put all sub tokens in it // Check if Action has been initalized for this rule if (curr_action != NULL) { // If current action exists, make a new action and set current action to it curr_action->next_act = malloc(sizeof(Action)); curr_action = curr_action->next_act; } else { // If current action doesn't exist, this means we need to initalize the first action and set it to be the current action curr_rule->actions = malloc(sizeof(Action)); curr_action = curr_rule->actions; } // Copy arguments from temp array to curr_action->args curr_action->args = malloc(sizeof(char *) * (num + 1)); for (int i = 0; i < num; i++) { curr_action->args[i] = malloc(sizeof(char) * (strlen(temp_array[i]) + 1)); if (curr_action->args[i] == NULL) { perror("malloc"); exit(1); } strcpy(curr_action->args[i], temp_array[i]); } }
null
null
63c6489e5f004bf4898cfe23
2023-03-18T14:45:54.467Z
Help Write Code
v2
null
null
null
/* Evaluate the rule in rules corresponding to the given target. If target is NULL, evaluate the first rule instead. If pflag is 0, evaluate each dependency in sequence. If pflag is 1, then evaluate each dependency in parallel (by creating one new process per dependency). In this case, the parent process will wait until all child processes have terminated before checking dependency modified times to decide whether to execute the actions. */
63c6489e5f004bf4898cfe23
2023-03-18T16:03:18.894Z
Help Write Code
v2
null
null
null
/* Evaluate the rule in rules corresponding to the given target. If target is NULL, evaluate the first rule instead. If pflag is 0, evaluate each dependency in sequence. If pflag is 1, then evaluate each dependency in parallel (by creating one new process per dependency). In this case, the parent process will wait until all child processes have terminated before checking dependency modified times to decide whether to execute the actions. */ void run_make(char *target, Rule *rules, int pflag) {
63c6489e5f004bf4898cfe23
2023-03-18T17:31:04.114Z
Explain Code
v2
null
struct stat st; struct timespec tr_time; the_time = stat(target_rule->target, &st);
null
null
63c648a35f004bf4898cfe50
2023-01-27T16:47:10.035Z
Help Fix Code
v1
null
#include <stdlib.h> #include <stdio.h> /* * 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 composed of * exactly the correct number of integers. The values should be returned * through a pointer parameter passed in as the first argument. * * See the main function for an example call to fib. * Pay attention to the expected type of fib's parameters. */ /* Write your solution here */ void fib(int **sequence, int n){ *sequence = malloc(sizeof(int*) * n); if (n >=2){ *sequence[0] = 0; *sequence[1] = 1; for(int i = 2; i < 1 ; i++){ *sequence[i] = *sequence[i-2] + *sequence[i-1]; } } else{ for(int i =0; i < n; i++){ *sequence[i] = i; } } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
fibonacci sequence in dynamically allocated array
null
63c648a35f004bf4898cfe50
2023-01-27T16:51:00.050Z
Help Fix Code
v1
null
void fib(int **sequence, int n){ *sequence = malloc(sizeof(int) * n); if (n >=2){ *sequence[0] = 0; *sequence[1] = 1; for(int i = 2; i < n ; i++){ *sequence[i] = *sequence[i-2] + *sequence[i-1]; } } else{ for(int i =0; i < n; i++){ *sequence[i] = i; } } }
in a dynamically allocated array, generate the first n numbers of the fibonacci sequence
null
63c648a35f004bf4898cfe50
2023-01-27T16:52:22.166Z
Help Fix Code
v1
null
void fib(int **sequence, int n){ *sequence = malloc(sizeof(int) * n); if (n >=2){ *sequence[0] = 0; *sequence[1] = 1; for(int i = 2; i < n ; i++){ sequence[i] = sequence[i-2] + sequence[i-1]; } } else{ for(int i =0; i < n; i++){ *sequence[i] = i; } } }
fibonacci sequence in dynamic array
null
63c648a35f004bf4898cfe50
2023-01-27T17:00:52.213Z
Help Fix Code
v1
null
void fib(int **sequence, int n){ *sequence = malloc(sizeof(int) * n); *sequence[0] = 0; *sequence[1] = 1; for(int i = 2; i < n ; i++){ *sequence[i] = *sequence[i-2] + *sequence[i-1]; } }
store fibonacci in a pointer to an array
null
63c648a35f004bf4898cfe50
2023-01-27T17:03:20.486Z
Question from Code
v1
why is there a segmentation fault
#include <stdlib.h> #include <stdio.h> /* * 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 composed of * exactly the correct number of integers. The values should be returned * through a pointer parameter passed in as the first argument. * * See the main function for an example call to fib. * Pay attention to the expected type of fib's parameters. */ /* Write your solution here */ void fib(int **sequence, int n){ *sequence = malloc(sizeof(int) * n); *sequence[0] = 0; *sequence[1] = 1; for(int i = 2; i < n ; i++){ *sequence[i] = *sequence[i-2] + *sequence[i-1]; } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
null
null
63c648a35f004bf4898cfe50
2023-01-27T17:07:38.397Z
Help Fix Code
v1
null
#include <stdlib.h> #include <stdio.h> /* * 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 composed of * exactly the correct number of integers. The values should be returned * through a pointer parameter passed in as the first argument. * * See the main function for an example call to fib. * Pay attention to the expected type of fib's parameters. */ /* Write your solution here */ void fib(int **sequence, int n){ *sequence = malloc(sizeof(int) * n); *sequence[0] = 0; *sequence[1] = 1; for(int i = 2; i < n ; i++){ *sequence[i] = *sequence[i-2] + *sequence[i-1]; } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
store values in an array from a pointer
null
63c648a35f004bf4898cfe50
2023-01-27T17:09:21.486Z
Explain Code
v1
null
#include <stdlib.h> #include <stdio.h> /* * 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 composed of * exactly the correct number of integers. The values should be returned * through a pointer parameter passed in as the first argument. * * See the main function for an example call to fib. * Pay attention to the expected type of fib's parameters. */ /* Write your solution here */ void fib(int **sequence, int n){ *sequence = malloc(sizeof(int) * n); *sequence[0] = 0; *sequence[1] = 1; for(int i = 2; i < n ; i++){ *sequence[i] = *sequence[i-2] + *sequence[i-1]; } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
null
null
63c648a35f004bf4898cfe50
2023-01-27T17:09:27.607Z
Explain Code
v1
null
#include <stdlib.h> #include <stdio.h> /* * 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 composed of * exactly the correct number of integers. The values should be returned * through a pointer parameter passed in as the first argument. * * See the main function for an example call to fib. * Pay attention to the expected type of fib's parameters. */ /* Write your solution here */ void fib(int **sequence, int n){ *sequence = malloc(sizeof(int) * n); *sequence[0] = 0; *sequence[1] = 1; for(int i = 2; i < n ; i++){ *sequence[i] = *sequence[i-2] + *sequence[i-1]; } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
null
null
63c648a35f004bf4898cfe50
2023-02-03T18:55:43.079Z
General Question
v1
how do i concatenate a char into a char array and stop copying when all the bytes have been used
null
null
null
63c648a35f004bf4898cfe50
2023-02-10T18:15:15.364Z
Question from Code
v1
* 1. First, allocate space for m `struct pixel *` values, where m is the * height of the image. Each pointer will eventually point to one row of * pixel data. * 2. For each pointer you just allocated, initialize it to point to * heap-allocated space for an entire row of pixel data. * 3. Use the given file and pixel_array_offset to initialize the actual * struct pixel values. Assume that `sizeof(struct pixel) == 3`, which is * consistent with the bitmap file format. * NOTE: We've tested this assumption on the Teaching Lab machines, but * if you're trying to work on your own computer, we strongly recommend * checking this assumption! * 4. Return the address of the first `struct pixel *` you initialized.
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { struct pixel **m = malloc(height * sizeof(struct pixel *)); // instruction 1 for (int i = 0; i < height; i++){ m[i] = malloc(row * sizeof(struct pixel * )); // instruction 2 fseek(image, pixel_array_offset + i * width * 3, SEEK_SET); // instruction 3 fread(m[i], sizeof(struct pixel), width, image); } }
null
null
63c648a35f004bf4898cfe50
2023-02-10T18:16:29.308Z
Explain Code
v1
null
* 1. First, allocate space for m `struct pixel *` values, where m is the * height of the image. Each pointer will eventually point to one row of * pixel data. * 2. For each pointer you just allocated, initialize it to point to * heap-allocated space for an entire row of pixel data. * 3. Use the given file and pixel_array_offset to initialize the actual * struct pixel values. Assume that `sizeof(struct pixel) == 3`, which is * consistent with the bitmap file format. * NOTE: We've tested this assumption on the Teaching Lab machines, but * if you're trying to work on your own computer, we strongly recommend * checking this assumption! * 4. Return the address of the first `struct pixel *` you initialized.
null
null
63c648a35f004bf4898cfe50
2023-02-10T18:17:41.271Z
Explain Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { struct pixel **m = malloc(height * sizeof(struct pixel *)); // instruction 1 for (int i = 0; i < height; i++){ m[i] = malloc(row * sizeof(struct pixel * )); // instruction 2 fseek(image, pixel_array_offset + i * width * 3, SEEK_SET); // instruction 3 fread(m[i], sizeof(struct pixel), width, image); } }
null
null
63c648a35f004bf4898cfe50
2023-02-10T18:20:45.950Z
Help Fix Code
v1
null
struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { struct pixel **m = malloc(height * sizeof(struct pixel *)); // instruction 1 for (int i = 0; i < height; i++){ m[i] = malloc(row * sizeof(struct pixel * )); // instruction 2 fseek(image, pixel_array_offset + i * width * 3, SEEK_SET); // instruction 3 fread(m[i], sizeof(struct pixel), width, image); } }
First, allocate space for m `struct pixel *` values, where m is the height of the image. Each pointer will eventually point to one row of pixel data.
null
63c648a35f004bf4898cfe50
2023-02-10T18:27:48.388Z
Question from Code
v1
is this correct
#include <stdio.h> #include <stdlib.h> #include "bitmap.h" /* * Read in the location of the pixel array, the image width, and the image * height in the given bitmap file. */ void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { fseek(image, 10, SEEK_SET); // first offset is at byte 10 fread(pixel_array_offset, 4, 1, image); fseek(image, 18, SEEK_SET); // second offset at byte 18 fread(width, 4, 1, image); fseek(image, 22, SEEK_SET); //third offset at byte 22 fread(height, 4, 1, image); } /* * Read in pixel array by following these instructions: * * 1. First, allocate space for m `struct pixel *` values, where m is the * height of the image. Each pointer will eventually point to one row of * pixel data. * 2. For each pointer you just allocated, initialize it to point to * heap-allocated space for an entire row of pixel data. * 3. Use the given file and pixel_array_offset to initialize the actual * struct pixel values. Assume that `sizeof(struct pixel) == 3`, which is * consistent with the bitmap file format. * NOTE: We've tested this assumption on the Teaching Lab machines, but * if you're trying to work on your own computer, we strongly recommend * checking this assumption! * 4. Return the address of the first `struct pixel *` you initialized. */ struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) { struct pixel **m = malloc(height * sizeof(struct pixel *)); // instruction 1 for (int i = 0; i < height; i++){ m[i] = malloc(width * sizeof(struct pixel * )); // instruction 2 fseek(image, pixel_array_offset + i * width * 3, SEEK_SET); // instruction 3 fread(m[i], sizeof(struct pixel), width, image); } return m; } /* * Print the blue, green, and red colour values of a pixel. * You don't need to change this function. */ void print_pixel(struct pixel p) { printf("(%u, %u, %u)\n", p.blue, p.green, p.red); }
null
null
63c648a35f004bf4898cfe50
2023-02-13T23:42:50.235Z
General Question
v1
How do I cast a variable (const User *) to a (User *)
null
null
null
63c648a35f004bf4898cfe50
2023-02-14T00:32:27.668Z
General Question
v1
#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; 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; /* * Create a new user with the given name. Insert it at the tail of the list * of users whose head is pointed to by *user_ptr_add. * * Return: * - 0 if successful * - 1 if a user by this name already exists in this list * - 2 if the given name cannot fit in the 'name' array * (don't forget about the null terminator) */ int create_user(const char *name, User **user_ptr_add);
null
null
null
63c648a35f004bf4898cfe50
2023-02-14T00:33:40.334Z
Explain Code
v1
null
int create_user(const char *name, User **user_ptr_add) { User *user_in_list = *user_ptr_add; if(strlen(name) >= MAX_NAME){ return 2; } while(user_in_list != NULL){ if(strcmp(user_in_list->name, name) == 0){ return 1; } else{ user_in_list = user_in_list->next; } } // at this point, the while loop should have either returned 1 or user_in_list is NULL // create new user on the heap so we can access it indefinitely User *new_user = malloc(sizeof(User)); strcpy(new_user->name, name); // set the name new_user->first_post = NULL; // set the first post to NULL for (int i = 0; i < MAX_FRIENDS; i++) { // set to no friends (NULL) for each index new_user->friends[i] = NULL; } if(*user_ptr_add == NULL){ // add the new user to the end of the list as asked *user_ptr_add = new_user; } else{ user_in_list = *user_ptr_add; // reinitialize the value while(user_in_list->next != NULL){ user_in_list = user_in_list->next; } user_in_list->next = new_user; } // should only be successful at this point return 0; }
null
null
63c648a35f004bf4898cfe50
2023-02-14T19:20:40.285Z
Question from Code
v1
can you help to initialize any uninitialized values in this code?
int create_user(const char *name, User **user_ptr_add) { User *user_in_list = *user_ptr_add; if(strlen(name) >= MAX_NAME){ return 2; } User *null_ptr = NULL; while(user_in_list != null_ptr){ if(user_in_list->name && strcmp(user_in_list->name, name) == 0){ return 1; } else{ user_in_list = user_in_list->next; } }
null
null
63c648a35f004bf4898cfe50
2023-02-14T19:21:26.605Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { User *user_in_list = *user_ptr_add; if(strlen(name) >= MAX_NAME){ return 2; } User *null_ptr = NULL; while(user_in_list != null_ptr){ if(user_in_list->name && strcmp(user_in_list->name, name) == 0){ return 1; } else{ user_in_list = user_in_list->next; } }
how can i initialize user_ptr_add
null
63c648a35f004bf4898cfe50
2023-02-14T19:22:13.388Z
Question from Code
v1
how do i initialize user_in_list while trying to make it take the value of the parameter
int create_user(const char *name, User **user_ptr_add) { User *user_in_list = *user_ptr_add; if(strlen(name) >= MAX_NAME){ return 2; } User *null_ptr = NULL; while(user_in_list != null_ptr){ if(user_in_list->name && strcmp(user_in_list->name, name) == 0){ return 1; } else{ user_in_list = user_in_list->next; } }
null
null
63c648a35f004bf4898cfe50
2023-03-13T02:03:33.385Z
Question from Code
v2
why am i getting a segmentation fault
void add_dependencies(Rule *rcurr, Dependency *dhead, Dependency *dcurr, char *token) { // go through all dependencies while ((token = strtok(NULL, " \n")) != NULL) { Dependency *dep = malloc(sizeof(Dependency)); // we will modify these later, set to NULL for now dep->rule = NULL; dep->next_dep = NULL; // if this is the first dependency, replace if (dhead == NULL) { dhead = dep; dcurr = dep; } // otherwise, append to the next dependency else { dcurr->next_dep = dep; dcurr = dep; } // if this is the first dependency for the list, replace if (rcurr->dependencies == NULL) { rcurr->dependencies = dep; } // otherwise append to next else { dcurr->next_dep = rcurr->dependencies; rcurr->dependencies = dep; } } while (dcurr->next_dep != NULL) { dcurr = dcurr->next_dep; } }
null
null
63c648a35f004bf4898cfe50
2023-03-13T02:09:02.471Z
Help Write Code
v2
null
null
null
Your first task is to implement parse_file, so that it reads a makefile and constructs a corresponding linked data structure.
63c648a35f004bf4898cfe50
2023-03-13T02:11:34.666Z
Help Fix Code
v2
Your first task is to implement parse_file, so that it reads a makefile and constructs a corresponding linked data structure.
Rule *parse_file(FILE *fp) { Rule *rhead = NULL; Rule *rcurr = NULL; Dependency *dhead = NULL; Dependency *dcurr = NULL; Action *ahead = NULL; Action *acurr = NULL; char curr_line[MAXLINE]; char *token; while(fgets(curr_line, MAXLINE, fp)!= NULL){ // ignore empty line and comments if(is_comment_or_empty(curr_line)){ continue; } // checking if target line if ((token = strtok(curr_line, " :\n")) != NULL){ Rule *rule = create_rule(token); // if this is the first rule, replace if(rhead == NULL){ rhead = rule; rcurr = rule; } // otherwise, append to the next rule else{ rcurr->next_rule = rule; rcurr = rule; } } // add dependencies to current rule, will not execute if token is NULL add_dependencies(rcurr, dhead, dcurr, token); // if line starts with a tab, create a new action if((token = strtok(curr_line, "\n")) != NULL && strcmp(token, "\t") == 0){ int max_args = 0; Action *act = create_action(token, curr_line, &max_args); add_arguments(act, token, max_args); // add to current Rule's list if(ahead == NULL){ ahead = act; acurr = act; } else{ acurr->next_act = act; acurr = act; } } } fclose(fp); return rhead; }
null
null
63c648a35f004bf4898cfe50
2023-03-13T02:13:09.248Z
Help Fix Code
v2
create a linked list of dependency structs
/*Adds dependencies to the rule*/ void add_dependencies(Rule *rcurr, Dependency *dhead, Dependency *dcurr, char *token){ // go through all dependencies while((token = strtok(NULL, " \n")) != NULL){ Dependency *dep = malloc(sizeof(Dependency)); // we will modify these later, set to NULL for now dep->rule = NULL; dep->next_dep = NULL; // if this is the first dependency, replace if (dhead == NULL){ dhead = dep; dcurr = dep; } // otherwise, append to the next dependency else{ dcurr->next_dep = dep; dcurr = dep; } // if this is the first dependency for the list, replace if(rcurr->dependencies == NULL){ rcurr->dependencies = dep; } // otherwise append to next else{ dcurr->next_dep = rcurr->dependencies; rcurr->dependencies = dep; } } while (dcurr != NULL && dcurr->next_dep != NULL) { dcurr = dcurr->next_dep; } }
null
null
63c648a35f004bf4898cfe50
2023-03-13T02:15:39.867Z
Help Write Code
v2
null
null
null
can you write a function to create a linked list of structs?
63c648a35f004bf4898cfe50
2023-03-13T03:28:31.645Z
General Question
v2
if a struct has a char* attribute, do we need to allocate memory using malloc to assign a value to it
null
null
null
63c648a45f004bf4898cfe55
2023-02-11T17:16:04.218Z
Explain Code
v1
null
#include <stdio.h> #include <stdlib.h> typedef struct node { int value; struct node *next; } Node; Node *create_node(int num, Node *next) { Node *new_node = malloc(sizeof(Node)); new_node->value = num; new_node->next = next; return new_node; } int main() { Node *front = NULL; front = create_node(3, front); front = create_node(2, front); front = create_node(1, front); Node *curr = front; while (curr != NULL) { printf("%d\n", curr->value); curr = curr->next; } return 0; }
null
null
63c648a55f004bf4898cfe5f
2023-03-13T00:24:02.329Z
Help Fix Code
v2
tokenize strings
int main() { char *line = "main : linked_list.o main.o"; char **tokens = tokenize(line); int i = 0; while (tokens[i] != NULL) { printf("%s\n", tokens[i]); i++; } return 0; } char **tokenize(char* line) { int i = 0; char *token = strtok(line, " "); char **tokens; while (token != NULL) { tokens[i] = token; i++; token = strtok(NULL, " "); } return tokens; }
null
null
63c648a55f004bf4898cfe5f
2023-03-13T00:25:08.725Z
Help Fix Code
v2
split a string into an array of strings
int main() { char *line = "main : linked_list.o main.o"; char **tokens = tokenize(line); int i = 0; while (tokens[i] != NULL) { printf("%s\n", tokens[i]); i++; } return 0; } char **tokenize(char* line) { int i = 0; char *token = strtok(line, " "); char **tokens; while (token != NULL) { tokens[i] = token; i++; token = strtok(NULL, " "); } return tokens; }
null
null
63c648a55f004bf4898cfe5f
2023-03-13T00:26:10.518Z
Help Fix Code
v2
split a string into an array of strings
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *line = "main : linked_list.o main.o"; char **tokens = tokenize(line); int i = 0; while (tokens[i] != NULL) { printf("%s\n", tokens[i]); i++; } return 0; } char **tokenize(char* line) { int i = 0; char *token = strtok(line, " "); char **tokens; while (token != NULL) { tokens[i] = token; i++; token = strtok(NULL, " "); } return tokens; }
null
null
63c648a55f004bf4898cfe64
2023-03-10T04:40:08.370Z
General Question
v2
what does read function do?
null
null
null
63c648a55f004bf4898cfe64
2023-03-10T04:42:15.642Z
Explain Code
v2
null
int main(void){ int n, user_length; char userid[MAXLINE]; char password[MAXLINE]; if((n = read(STDIN_FILENO, userid, MAX_PASSWORD)) == -1) { perror("read"); exit(1); } else if(n == 0) { fprintf(stderr, "Error: could not read from stdin"); exit(1); } // Make sure user id is null-terminated if(n <= MAX_PASSWORD) { userid[n] ='\0'; } // Remove newline character if it exists char *newline; if((newline = strchr(userid, '\n')) != NULL) { *newline = '\0'; } if((n = read(STDIN_FILENO, password, MAX_PASSWORD)) == -1) { perror("read"); exit(1); } else if(n == 0) { fprintf(stderr, "Error: could not read from stdin"); exit(1); } // Make sure password is null-terminated if(n <= MAX_PASSWORD) { password[n] ='\0'; } // Remove newline character if it exists if((newline = strchr(password, '\n')) != NULL) { *newline = '\0'; }
null
null
63c648a65f004bf4898cfe69
2023-01-27T02:13:18.428Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> /* Return a pointer to an array of two dynamically allocated arrays of ints. The first array contains the elements of the input array s that are at even indices. The second array contains the elements of the input array s that are at odd indices. Do not allocate any more memory than necessary. You are not permitted to include math.h. You can do the math with modulo arithmetic and integer division. */ int **split_array(const int *s, int length) { int sp_even[length/2+length%2]; int sp_odd[length/2]; for (int i = 0; i < length; i++) { if (i%2 == 0) { sp_even[i/2] = s[i]; } else { sp_odd[i/2+1] = s[i]; } } int *sp2[] = {sp_even, sp_odd}; int *(*sp)[2] = &sp2; return *sp; } /* Return a pointer to an array of ints with size elements. - strs is an array of strings where each element is the string representation of an integer. - size is the size of the array */ int *build_array(char **strs, int size) { int *arr = malloc(size * sizeof(int)); for (int i = 0; i < size; i++) { (arr)[i] = strtol((const char *) (*strs)[i], NULL, 10); } return arr; } int main(int argc, char **argv) { /* Replace the comments in the next two lines with the appropriate arguments. Do not add any additional lines of code to the main function or make other changes. */ int *full_array = build_array(&argv[1], argc); int **result = split_array(full_array, argc); printf("Original array:\n"); for (int i = 0; i < argc - 1; i++) { printf("%d ", full_array[i]); } printf("\n"); printf("result[0]:\n"); for (int i = 0; i < argc / 2; i++) { printf("%d ", result[0][i]); } printf("\n"); printf("result[1]:\n"); for (int i = 0; i < (argc - 1) / 2; i++) { printf("%d ", result[1][i]); } printf("\n"); free(full_array); free(result[0]); free(result[1]); free(result); return 0; }
Return a pointer to an array of two dynamically allocated arrays of ints. The first array contains the elements of the input array s that are at even indices. The second array contains the elements of the input array s that are at odd indices. Do not allocate any more memory than necessary. You are not permitted to include math.h. You can do the math with modulo arithmetic and integer division.
null
63c648a65f004bf4898cfe69
2023-01-27T02:16:06.580Z
Help Fix Code
v1
null
/* Return a pointer to an array of two dynamically allocated arrays of ints. The first array contains the elements of the input array s that are at even indices. The second array contains the elements of the input array s that are at odd indices. Do not allocate any more memory than necessary. You are not permitted to include math.h. You can do the math with modulo arithmetic and integer division. */ int **split_array(const int *s, int length) { int sp_even[length/2+length%2]; int sp_odd[length/2]; for (int i = 0; i < length; i++) { if (i%2 == 0) { sp_even[i/2] = s[i]; } else { sp_odd[i/2+1] = s[i]; } } int *sp2[] = {sp_even, sp_odd}; int *(*sp)[2] = &sp2; return *sp; }
Return a pointer to an array of two dynamically allocated arrays of ints. The first array contains the elements of the input array s that are at even indices. The second array contains the elements of the input array s that are at odd indices. Do not allocate any more memory than necessary. You are not permitted to include math.h. You can do the math with modulo arithmetic and integer division
null
63c648a65f004bf4898cfe69
2023-01-27T02:18:56.292Z
Help Fix Code
v1
null
/* Return a pointer to an array of ints with size elements. - strs is an array of strings where each element is the string representation of an integer. - size is the size of the array */ int *build_array(char **strs, int size) { int *arr = malloc(size * sizeof(int)); for (int i = 0; i < size; i++) { (arr)[i] = strtol((const char *) (*strs)[i], NULL, 10); } return arr; }
/* Return a pointer to an array of ints with size elements. - strs is an array of strings where each element is the string representation of an integer. - size is the size of the array */
null
63c648a65f004bf4898cfe69
2023-01-27T02:19:58.605Z
Help Fix Code
v1
null
/* Return a pointer to an array of ints with size elements. - strs is an array of strings where each element is the string representation of an integer. - size is the size of the array */ int *build_array(char **strs, int size) { int *arr = malloc(size * sizeof(int)); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; }
Return a pointer to an array of ints with size elements. - strs is an array of strings where each element is the string representation of an integer. - size is the size of the array
null
63c648a65f004bf4898cfe69
2023-01-27T02:21:15.956Z
Help Fix Code
v1
null
/* Return a pointer to an array of ints with size elements. - strs is an array of strings where each element is the string representation of an integer. - size is the size of the array */ int *build_array(char **strs, int size) { int *arr = malloc(size * sizeof(int)); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; }
Return a pointer to an array of ints with size elements. - strs is an array of strings where each element is the string representation of an integer. - size is the size of the array
null
63c648a65f004bf4898cfe69
2023-01-27T03:42:38.926Z
General Question
v1
set pointer array element
null
null
null
63c648a65f004bf4898cfe69
2023-01-27T03:44:40.562Z
General Question
v1
dynamically allocate array
null
null
null
63c648a65f004bf4898cfe69
2023-01-27T03:45:32.118Z
General Question
v1
access element in double pointer
null
null
null
63c648a65f004bf4898cfe69
2023-01-27T03:46:47.578Z
General Question
v1
strtol how to use
null
null
null
63c648a65f004bf4898cfe69
2023-01-27T04:04:39.965Z
General Question
v1
get array of strings from arguments
null
null
null
63c648a65f004bf4898cfe69
2023-01-27T04:05:04.632Z
General Question
v1
get array of strings from terminal argument inputs
null
null
null
63c648a65f004bf4898cfe69
2023-01-27T04:06:07.127Z
General Question
v1
return array without first element
null
null
null
63c648a65f004bf4898cfe69
2023-01-27T04:06:58.162Z
General Question
v1
go to next pointer
null
null
null
63c648a65f004bf4898cfe6e
2023-01-23T23:43:56.946Z
Question from Code
v1
set the allocated_amount variable to the exact amount of space that should be allocated and pointed to by float *rainfall.
int main() { int allocated_amount; // Set the value of allocated_amount: float *rainfall = 42.6; allocated_amount = malloc(rainfall * sizeof(float)); return 0;
null
null
63c648a65f004bf4898cfe6e
2023-01-23T23:46:23.369Z
Question from Code
v1
8:22: warning: assignment to 'int' from 'void *' makes integer from pointer without a cast [-Wint-conversion]
int main() { int allocated_amount; // Set the value of allocated_amount: allocated_amount = malloc(42.6 * sizeof(float)); return 0;
null
null
63c648a65f004bf4898cfe6e
2023-01-23T23:48:07.366Z
Help Fix Code
v1
null
int main() { int allocated_amount; // Set the value of allocated_amount: allocated_amount = malloc(42.6 * sizeof(float)); return 0;
need to cast void * to int
null
63c648a65f004bf4898cfe6e
2023-01-23T23:49:32.902Z
Help Fix Code
v1
null
int main() { int allocated_amount; // Set the value of allocated_amount: allocated_amount = (int) malloc(42.6 * sizeof(float)); return 0;
8:24: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
null
63c648a65f004bf4898cfe6e
2023-01-23T23:52:49.321Z
Help Fix Code
v1
null
int main(int argc, char **argv) { float *rainfall; float rain_today; return 0; }
Assign the amount in rain_today to the space rainfall points to.
null
63c648a65f004bf4898cfe6e
2023-01-23T23:55:01.979Z
Help Fix Code
v1
null
int main(int argc, char **argv) { float *rainfall; float rain_today; return 0; }
// rainfall has been dynamically allocated space for a floating point number. // Both rainfall and rain_today have been initialized in hidden code. // Assign the amount in rain_today to the space rainfall points to.
null
63c648a65f004bf4898cfe6e
2023-01-24T00:10:05.870Z
Explain Code
v1
null
int main(int argc, char **argv) { float *rainfall; float rain_today; return 0; }
null
null
63c648a65f004bf4898cfe6e
2023-01-24T01:08:39.256Z
Help Fix Code
v1
null
int main() { char **last_names; **last_names = malloc(sizeof(char*) * 4); last_names[0] = malloc(sizeof(char) * 20); last_names[1] = malloc(sizeof(char) * 20); last_names[2] = malloc(sizeof(char) * 20); last_names[3] = malloc(sizeof(char) * 20);
// Assign a dynamically allocated char * array of length 4 to last_names. // Then, allocate a character array of length 20 for each element of the array // pointed to by last_names.
null
63c648a65f004bf4898cfe6e
2023-01-24T01:10:59.824Z
General Question
v1
When we allocate memory we need to provide the size of the block of memory we need.
null
null
null
63c648a65f004bf4898cfe6e
2023-01-24T01:11:29.666Z
General Question
v1
do we need to provide the size of the block of memory we need when allocating memory
null
null
null
63c648a65f004bf4898cfe6e
2023-01-24T01:12:04.580Z
General Question
v1
do we need to provide the size of the block of memory we are finished using when we deallocate memory
null
null
null
63c648a65f004bf4898cfe6e
2023-01-24T01:12:34.055Z
General Question
v1
when calling free do we need to provide the address of the block of memory we are deallocating
null
null
null
63c648a65f004bf4898cfe6e
2023-01-24T01:13:31.696Z
General Question
v1
does a call to free reset the values in the deallocated memory to null
null
null
null
63c648a65f004bf4898cfe6e
2023-01-24T01:14:28.948Z
General Question
v1
when does an ENOMEM error occur
null
null
null
63c648a65f004bf4898cfe6e
2023-01-24T01:14:49.746Z
General Question
v1
what is a memory leak
null
null
null
63c648a65f004bf4898cfe6e
2023-01-24T01:17:59.127Z
Help Fix Code
v1
null
#include <stdio.h> int main() { int error; FILE *scores_file; scores_file = fopen("high scores.txt", "w"); error = fclose(scores_file); if (error != 0) { fprintf(stderr, "fclose failed\n"); return 1; } return 0; }
open a text file called high_scores.txt for reading which is not located in the same directory as the executable
null
63c648a65f004bf4898cfe6e
2023-01-24T01:19:01.350Z
Help Fix Code
v1
null
#include <stdio.h> int main() { int error; FILE *scores_file; scores_file = fopen("high scores.txt", "r"); error = fclose(scores_file); if (error != 0) { fprintf(stderr, "fclose failed\n"); return 1; } return 0; }
open a text file called high_scores.txt for reading which is not located in the same directory as the executable
null
63c648a65f004bf4898cfe6e
2023-01-26T23:19:11.245Z
Help Fix Code
v1
null
#include <stdio.h> #include <string.h> #include <stdlib.h> struct contact { char name[30]; int phone_number; char address[30]; }; // update_contact goes here void update_contact(struct contact *c) { c->phone_number = 111111l; strcpy((*c).name, "change name"); (*c).phone_number = 111111111; strcpy((*c).address, "new address"); } int main(int argc, char **argv) { struct contact friend; // set initial values for friend strcpy(friend.name, "Jane Doe"); friend.phone_number = 377177377; strcpy(friend.address, "3771 University Avenue"); char *name; int number; char *address; // in hidden code set values for these 3 variables // call update_contact to change the values in friend update_contact(&friend, name, number, address); return 0;
Given the following program, write the function update_contact which takes a pointer to the struct contact, a new name, a new number, and a new address to change the struct’s members. Look at the function call for the order of arguments and appropriate types.
null
63c648a65f004bf4898cfe6e
2023-01-27T04:19:59.898Z
Help Fix Code
v1
null
#include <stdio.h> #include <string.h> #include <stdlib.h> struct contact { char name[30]; int phone_number; char address[30]; }; // update_contact goes here void update_contact(struct contact *c) { } int main(int argc, char **argv) { struct contact friend; // set initial values for friend strcpy(friend.name, "Jane Doe"); friend.phone_number = 377177377; strcpy(friend.address, "3771 University Avenue"); char *name; int number; char *address; // in hidden code set values for these 3 variables // call update_contact to change the values in friend update_contact(&friend, name, number, address); return 0;
Given the following program, write the function update_contact which takes a pointer to the struct contact, a new name, a new number, and a new address to change the struct’s members. Look at the function call for the order of arguments and appropriate types.
null
63c648a65f004bf4898cfe6e
2023-01-27T04:24:45.799Z
Help Fix Code
v1
null
#include <stdio.h> #include <string.h> #include <stdlib.h> struct contact { char name[30]; int phone_number; char address[30]; }; // update_contact goes here void update_contact(struct contact *c, char &name, int number, char *address) { p = &c; p->name =name; p->phone_number = number; p->address = address; } int main(int argc, char **argv) { struct contact friend; // set initial values for friend strcpy(friend.name, "Jane Doe"); friend.phone_number = 377177377; strcpy(friend.address, "3771 University Avenue"); char *name; int number; char *address; // in hidden code set values for these 3 variables // call update_contact to change the values in friend update_contact(&friend, name, number, address); return 0;
Given the following program, write the function update_contact which takes a pointer to the struct contact, a new name, a new number, and a new address to change the struct’s members. Look at the function call for the order of arguments and appropriate types.
null
63c648a65f004bf4898cfe6e
2023-01-27T04:40:41.797Z
Help Fix Code
v1
null
#include <stdio.h> #include <string.h> #include <stdlib.h> struct contact { char name[30]; int phone_number; char address[30]; }; // update_contact goes here void update_contact(struct contact *c, char *name, int number, char *address) { struct contact p; p = &c; strcpy(p->name, name); p->phone_number = number; strcpy(p->address, address); } int main(int argc, char **argv) { struct contact friend; // set initial values for friend strcpy(friend.name, "Jane Doe"); friend.phone_number = 377177377; strcpy(friend.address, "3771 University Avenue"); char *name; int number; char *address; // in hidden code set values for these 3 variables // call update_contact to change the values in friend update_contact(&friend, name, number, address); return 0;
Given the following program, write the function update_contact which takes a pointer to the struct contact, a new name, a new number, and a new address to change the struct’s members. Look at the function call for the order of arguments and appropriate types.
null
63c648a65f004bf4898cfe6e
2023-01-27T04:41:37.678Z
Help Fix Code
v1
null
// update_contact goes here void update_contact(struct contact *c, char *name, int number, char *address) { struct contact p; p = &c; strcpy(p->name, name); p->phone_number = number; strcpy(p->address, address); }
Given the following program, write the function update_contact which takes a pointer to the struct contact, a new name, a new number, and a new address to change the struct’s members. Look at the function call for the order of arguments and appropriate types.
null
63c648a65f004bf4898cfe6e
2023-01-27T04:43:17.734Z
Help Fix Code
v1
null
// update_contact goes here void update_contact(struct contact c, char *name, int number, char *address) { struct contact p; p = &c; strcpy(p->name, name); p->phone_number = number; strcpy(p->address, address); }
write the function update_contact which takes a pointer to the struct contact, a new name, a new number, and a new address to change the struct’s members.
null
63c648a65f004bf4898cfe6e
2023-01-27T22:26:54.392Z
General Question
v1
how to iterate through the digits of a given integer
null
null
null
63c648a65f004bf4898cfe6e
2023-01-27T22:35:47.452Z
General Question
v1
get first digit of a given integer
null
null
null
63c648a65f004bf4898cfe6e
2023-01-29T02:40:48.656Z
Help Fix Code
v1
null
int *result = malloc(sizeof(int) * 9); for (int i = 0; i < 9; i++) { char **product; *product = sin_array[i] * luhn[i]; if (product > 9) { // 2-digit number case result[i] = product[0] + product[1]; } else { result[i] = product; } }
if product is a two digits, add up the digits
null
63c648a65f004bf4898cfe6e
2023-01-29T02:56:19.247Z
General Question
v1
how to write or statement in if loop
null
null
null
63c648a65f004bf4898cfe6e
2023-01-29T02:57:11.120Z
General Question
v1
what arguments to put in printf if returning a message with strings
null
null
null
63c648a65f004bf4898cfe6e
2023-01-29T02:58:36.721Z
Question from Code
v1
how to add new line at the end of printf statement
if (populate_array(sin_int, *sin_array) == 1 || check_sin(*sin_array) == 1) { printf("Invalid SIN"\n); }
null
null
63c648a65f004bf4898cfe6e
2023-01-29T20:02:10.973Z
General Question
v1
arguments of scanf example
null
null
null
63c648a65f004bf4898cfe6e
2023-01-30T07:12:18.256Z
Help Fix Code
v1
null
int main(int argc, char **argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } char *permissions; int filesize; int count = 0; scanf("%*s %*d"); // NOTE: it says to ignore directories -- so you should use the first character to determine whether it's a directory or not. while (scanf("%10s %*d %*s %*s %d %*s %*d %*s %*s", permissions, &filesize) != EOF) { if (filesize > argv[1]) { if (argc == 3 && check_permissions(permissions, argv[2]) == 0) { count++; } else { // no permissions + file size > count++; } } } printf("%d/n", count); return 0; }
fix warning: variable 'permissions' is uninitialized when used here
null
63c648a65f004bf4898cfe6e
2023-01-30T07:20:21.172Z
Help Fix Code
v1
null
int main(int argc, char **argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } char *permissions[10]; int filesize; int count = 0; scanf("%*s %*d"); // NOTE: it says to ignore directories -- so you should use the first character to determine whether it's a directory or not. while (scanf("%10s %*d %*s %*s %d %*s %*d %*s %*s", permissions[1], &filesize) != EOF) { if (filesize > strtol(argv[1], NULL, 10)) { if (argc == 3 && check_permissions(permissions, argv[2]) == 0) { count++; } else { // no permissions + file size > count++; } } } printf("%d/n", count); return 0; }
fix line 45 warning: incompatible pointer types passing 'char *[10]' to parameter of type 'char *'
null
63c648a65f004bf4898cfe6e
2023-01-30T07:32:48.968Z
Help Fix Code
v1
null
int check_permissions(char *first[10], char *second[10]) { // first: permissions of a file, second: required permissions (input) int result = 0; for (int i = 0; i < 9; i++) { // need to omit first value -/d // for r w and x chars: check that sec[i] has that // if second is 'r' 'w' 'x' but first is not: second[i] != '-' && second[i] != first[i] if (second[i] != '-' && first[i] == '-') { // this should work, permissions are only formatted one way so either the write letter or it does not have that permission result = 1; } } return result; }
fix warning: comparison between pointer and integer ('char *' and 'int')
null
63c648a65f004bf4898cfe6e
2023-01-30T07:36:28.304Z
Help Fix Code
v1
null
int check_permissions(char *first[10], char *second[10]) { // first: permissions of a file, second: required permissions (input) int result = 0; for (int i = 0; i < 9; i++) { // need to omit first value -/d // for r w and x chars: check that sec[i] has that // if second is 'r' 'w' 'x' but first is not: second[i] != '-' && second[i] != first[i] if (second[i] != '-' && first[i] == '-') { // this should work, permissions are only formatted one way so either the write letter or it does not have that permission result = 1; } } return result; }
check if second[i] is equal to the char '-'
null
63c648a65f004bf4898cfe6e
2023-01-30T07:38:19.257Z
Help Fix Code
v1
null
int check_permissions(char *first[10], char *second[10]) { // first: permissions of a file, second: required permissions (input) int result = 0; for (int i = 0; i < 9; i++) { // need to omit first value -/d // for r w and x chars: check that sec[i] has that // if second is 'r' 'w' 'x' but first is not: second[i] != '-' && second[i] != first[i] if (second[i] != '-' && first[i] == '-') { // this should work, permissions are only formatted one way so either the write letter or it does not have that permission result = 1; } } return result; }
want second[i] to be a char instead of a char *
null
63c648a65f004bf4898cfe6e
2023-02-03T20:23:58.502Z
Help Write Code
v1
null
null
null
1. create an array 2. sort the array
63c648a65f004bf4898cfe6e
2023-02-03T20:25:35.005Z
Help Write Code
v1
null
null
null
create and sort array without using qsort
63c648a65f004bf4898cfe6e
2023-02-08T03:25:49.704Z
General Question
v1
what is bitmap
null
null
null
63c648a65f004bf4898cfe6e
2023-02-08T03:33:57.670Z
General Question
v1
read in the location of certain bytes of a file using fseek
null
null
null
63c648a65f004bf4898cfe6e
2023-02-08T03:40:26.553Z
General Question
v1
allocate space for a struct
null
null
null
63c648a65f004bf4898cfe6e
2023-02-08T03:45:36.023Z
Question from Code
v1
initialize allocated pointer 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) { // 1. struct pixel *pixels = malloc(sizeof(struct pixel) * height);
null
null