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
⌀ |
---|---|---|---|---|---|---|---|
63c648a85f004bf4898cfe7d | 2023-03-10T05:33:58.591Z | Help Write Code | v2 | null | null | null | Parse a makefile and create a linked list structure from it knowing that you already have struct rule node, struct action node and struct dependency node. |
63c648a85f004bf4898cfe7d | 2023-03-11T18:36:48.881Z | Help Write Code | v2 | null | null | null | Parse makeile and create a corresponding linked list data structure using strtok() and helper functions. |
63c648a85f004bf4898cfe7d | 2023-03-11T19:22:27.649Z | Help Write Code | v2 | null | null | null | Tokenize a makefile line by line |
63c648a85f004bf4898cfe7d | 2023-03-11T21:54:51.095Z | Help Write Code | v2 | null | null | null | How to put the actions of the makefile inside an array of arguments |
63c648a85f004bf4898cfe7d | 2023-03-11T21:57:53.382Z | Help Write Code | v2 | null | null | null | How to tokenize a line and put each element into an array |
63c648a85f004bf4898cfe7d | 2023-03-12T05:37:20.839Z | Help Write Code | v2 | null | null | null | Parse a makefile and store the actions as a struct_action node |
63c648a85f004bf4898cfe7d | 2023-03-12T17:03:14.963Z | Help Fix Code | v2 | Parse the makefile and create a linked list structure from it | /* 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) {
// Implement this function and remove the stubbed return statement below.
char *token;
char line[MAXLINE];
char **args[MAXLINE];
int i;
char *buffer;
Rule *new_rule;
Dependency *new_dependency;
while (fgets(line, sizeof(line), fp) != NULL) {
if (is_comment_or_empty(line) == 0 && line[0] != '\n') {
if (line[0] != '\t') {
token = strtok(line, " ");
create_rule(token, new_rule);
token = strtok(NULL, " ");
while (token != NULL) {
create_rule(token, new_rule);
add_dependency(new_rule);
token = strtok(NULL, " ");
}
} else {
token = strtok(line, ' ');
while (token != NULL) {
args[i] = token;
token = strtok(NULL, " ");
i++;
}
//args_to_string(args, token, ...);
}
}
}
return new_rule;
}
void create_rule(char *target, Rule *head) {
Rule *new_rule = malloc(sizeof(Rule));
Rule *curr;
strcpy(new_rule->target, target);
new_rule->dependencies = NULL;
new_rule->actions = NULL;
new_rule->next_rule = NULL;
if (head == NULL) {
head = new_rule;
} else {
curr = head;
while (curr->next_rule != NULL) {
if (strcmp(curr->target, target) == 0) { // To see if it already exists
break;
}
curr = curr->next_rule;
}
curr->next_rule = new_rule;
}
}
void add_dependency(Rule *rule) {
Dependency *new_dep = malloc(sizeof(Dependency));
new_dep->rule = rule;
new_dep->next_dep = NULL;
Dependency *curr;
while (curr->next_dep != NULL) {
curr = curr->next_dep;
}
curr->next_dep = new_dep;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-12T20:20:43.152Z | Help Fix Code | v2 | Parse the makefile and create a linked list data structure from it. | /* 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) {
// Implement this function and remove the stubbed return statement below.
char *token;
char line[MAXLINE];
char **args[MAXLINE];
int i;
char *buffer;
Rule *head = malloc(sizeof(Rule));
head->target = NULL;
head->dependencies = NULL;
head->actions = NULL;
head->next_rule = NULL;
Dependency *new_dependency;
while (fgets(line, sizeof(line), fp) != NULL) {
if (is_comment_or_empty(line) == 0 && line[0] != '\n') {
if (line[0] != '\t') {
token = strtok(line, " ");
create_rule(token, head);
token = strtok(NULL, " ");
while (token != NULL) {
create_rule(token, head);
add_dependency(head);
token = strtok(NULL, " ");
}
} else {
token = strtok(line, " ");
while (token != NULL) {
args[i] = token;
token = strtok(NULL, " ");
i++;
}
//args_to_string(args, token, ...);
}
}
}
return head;
}
void create_rule(char *target, Rule *head) {
Rule *new_rule = malloc(sizeof(Rule));
Rule *curr;
strcpy(new_rule->target, target);
new_rule->dependencies = NULL;
new_rule->actions = NULL;
new_rule->next_rule = NULL;
if (head == NULL) {
head = new_rule;
} else {
curr = head;
while (curr->next_rule != NULL) {
//if (strcmp(curr->target, target) == 0) { // To see if it already exists
//break;
//}
curr = curr->next_rule;
}
curr->next_rule = new_rule;
}
}
void add_dependency(Rule *rule) {
Dependency *new_dep = malloc(sizeof(Dependency));
new_dep->rule = rule;
new_dep->next_dep = NULL;
Dependency *curr;
while (curr->next_dep != NULL) {
curr = curr->next_dep;
}
curr->next_dep = new_dep;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-12T21:36:45.981Z | Help Fix Code | v2 | Parse the makefile and create a linked list structure | /* 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) {
// Implement this function and remove the stubbed return statement below.
char *token;
char line[MAXLINE];
char **args[MAXLINE];
int i;
char *buffer;
Rule *head = malloc(sizeof(Rule));
head->target = NULL;
head->dependencies = NULL;
head->actions = NULL;
head->next_rule = NULL;
Dependency *new_dependency;
while (fgets(line, sizeof(line), fp) != NULL) {
if (is_comment_or_empty(line) == 0 && line[0] != '\n') {
if (line[0] != '\t') {
token = strtok(line, " ");
create_rule(token, head);
token = strtok(NULL, " ");
while (token != NULL) {
create_rule(token, head);
add_dependency(head);
token = strtok(NULL, " ");
}
} else {
token = strtok(line, " ");
while (token != NULL) {
args[i] = token;
token = strtok(NULL, " ");
i++;
}
//args_to_string(args, token, ...);
}
}
}
return head;
}
void create_rule(char *target, Rule *head) {
Rule *new_rule = malloc(sizeof(Rule));
Rule *curr;
strcpy(new_rule->target, target);
new_rule->dependencies = NULL;
new_rule->actions = NULL;
new_rule->next_rule = NULL;
if (head == NULL) {
head = new_rule;
} else {
curr = head;
while (curr->next_rule != NULL) {
//if (strcmp(curr->target, target) == 0) { // To see if it already exists
//break;
//}
curr = curr->next_rule;
}
curr->next_rule = new_rule;
}
}
void add_dependency(Rule *rule) {
Dependency *new_dep = malloc(sizeof(Dependency));
new_dep->rule = rule;
new_dep->next_dep = NULL;
Dependency *curr;
while (curr->next_dep != NULL) {
curr = curr->next_dep;
}
curr->next_dep = new_dep;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-12T21:39:09.336Z | Help Write Code | v2 | null | null | null | A function called create rule that creates a linked list for a rule of a Makefile |
63c648a85f004bf4898cfe7d | 2023-03-13T01:54:42.725Z | Help Write Code | v2 | null | null | null | I want to iterate through an array of strings and add a null terminator to each element of the array. |
63c648a85f004bf4898cfe7d | 2023-03-13T02:48:57.659Z | Question from Code | v2 | I want to convert the actions in the makefile to an array of strings using this function. How do I do that. |
char *args_to_string(char **args, char *buffer, int size) {
buffer[0] = '\0';
int i = 0;
while (args[i] != NULL) {
strncat(buffer, args[i], size - strlen(buffer));
strncat(buffer, " ", size - strlen(buffer));
i++;
}
return buffer;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-13T02:52:35.201Z | Help Write Code | v2 | null | null | null | I want to convert the actions in the makefile to an array of strings |
63c648a85f004bf4898cfe7d | 2023-03-13T02:53:34.833Z | Help Write Code | v2 | null | null | null | I want to convert the actions in the makefile to an array of strings using strtok. |
63c648a85f004bf4898cfe7d | 2023-03-13T03:33:14.929Z | Explain Code | v2 | null |
char *args_to_string(char **args, char *buffer, int size) {
buffer[0] = '\0';
int i = 0;
while (args[i] != NULL) {
strncat(buffer, args[i], size - strlen(buffer));
strncat(buffer, " ", size - strlen(buffer));
i++;
}
return buffer;
}
| null | null |
63c648a85f004bf4898cfe7d | 2023-03-13T03:45:25.880Z | Help Write Code | v2 | null | null | null | Create a struct rule node for a dependency but also create a struct dependency node. Then assign the dependency to the corresponding target rule. |
63c648a85f004bf4898cfe7d | 2023-03-13T06:26:05.102Z | Help Fix Code | v2 | while parsing the makefile, when a dependency is found create a node for it then add to the dependency to the corresponding rule based on the target | typedef struct dep_node {
struct rule_node *rule;
struct dep_node *next_dep;
} Dependency;
typedef struct rule_node {
char *target;
Dependency *dependencies;
Action *actions;
struct rule_node *next_rule;
} Rule;
void add_dependency(Rule *head, char *target) {
Rule *curr = head;
Dependency *dependency = malloc(sizeof(Dependency));
while (curr != NULL) {
if (curr->target == target) {
curr->dependencies = dependency;
}
curr = curr->next_rule;
}
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-13T06:33:11.536Z | Help Fix Code | v2 | while parsing the makefile, when a dependency is found create a node for it then add to the dependency to the corresponding rule based on the target | typedef struct dep_node {
struct rule_node *rule;
struct dep_node *next_dep;
} Dependency;
typedef struct rule_node {
char *target;
Dependency *dependencies;
Action *actions;
struct rule_node *next_rule;
} Rule;
void add_dependency(Rule *head, char *target) {
Rule *curr = head;
Dependency *dependency = malloc(sizeof(Dependency));
while (curr != NULL) {
if (curr->target == target) {
curr->dependencies = dependency;
}
curr = curr->next_rule;
}
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-13T06:35:09.967Z | Help Fix Code | v2 | while parsing the makefile, when a dependency is found create a node for it then add to the dependency to the corresponding rule based on the target | void add_dependency(Rule *head, char *target) {
Rule *curr = head;
Dependency *dependency = malloc(sizeof(Dependency));
while (curr != NULL) {
if (curr->target == target) {
curr->dependencies = dependency;
}
curr = curr->next_rule;
}
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-13T06:36:12.605Z | Help Fix Code | v2 | while parsing the makefile, when a dependency is found create a node for it then add to the dependency to the corresponding rule based on the target | void add_dependency(Rule *head, char *target) {
Rule *curr = head;
Dependency *dependency = malloc(sizeof(Dependency));
while (curr != NULL) {
if (curr->target == target) {
curr->dependencies = dependency;
}
curr = curr->next_rule;
}
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-13T06:46:17.515Z | Help Write Code | v2 | null | null | null | while parsing the makefile, when a dependency is found create a node for it then add to the dependency to the corresponding rule based on the target. |
63c648a85f004bf4898cfe7d | 2023-03-13T06:50:05.497Z | Help Write Code | v2 | null | null | null | recursively evaluate each dependency rule. |
63c648a85f004bf4898cfe7d | 2023-03-13T14:13:34.841Z | Help Fix Code | v2 | while parsing the makefile, when a dependency is found create a node for it then add to the dependency to the corresponding rule based on the target. | void add_dependency(Rule *head, char *target) {
Rule *curr = head;
Dependency *dep = malloc(sizeof(Dependency));
dep->rule = NULL;
dep->next_dep = NULL;
while (curr->dependencies != NULL) {
if (curr->target == target) {
curr->dependencies = dep;
}
curr = curr->next_rule;
}
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-13T14:15:56.735Z | Help Fix Code | v2 | while parsing the makefile, when a dependency is found create a node for it then add to the dependency to the corresponding rule based on the target. | void add_dependency(Rule *head, char *target) {
Rule *curr = head;
Dependency *dep = malloc(sizeof(Dependency));
dep->rule = NULL;
dep->next_dep = NULL;
while (curr != NULL) {
if (curr->target == target) {
curr->dependencies = dep;
}
curr = curr->next_rule;
}
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-13T14:16:55.439Z | Help Write Code | v2 | null | null | null | while parsing the makefile, when a dependency is found create a node for it then add to the dependency to the corresponding rule based on the target. |
63c648a85f004bf4898cfe7d | 2023-03-13T14:29:58.283Z | Help Write Code | v2 | null | null | null | Add a dependency to the corresponding rule |
63c648a85f004bf4898cfe7d | 2023-03-13T23:13:34.862Z | Help Fix Code | v2 | Add a dependency to the corresponding rule | void add_dependency(Rule *current_rule, Rule *dep_rule, char *token){
Rule *curr;
Dependency *dep = malloc(sizeof(Dependency));
dep->rule = dep_rule;
dep->next_dep = NULL;
if (current_rule->dependencies == NULL) {
current_rule->dependencies = dep;
} else {
curr = current_rule;
while (curr->dependencies != NULL) {
curr = curr->next_rule;
}
curr->dependencies->next_dep = dep->next_dep;
}
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-14T17:19:01.226Z | Help Write Code | v2 | null | null | null | Update each of the dependencies. In other words, recursively evaluate each dependency rule. |
63c648a85f004bf4898cfe7d | 2023-03-14T18:07:32.343Z | Help Fix Code | v2 | Iterate through the actions and add an action at the end. | if (current_rule->actions == NULL) {
current_rule->actions = new_act;
} else {
curr = current_rule;
while (curr->actions->next_act != NULL) {
curr->actions = curr->actions->next_act;
}
curr->actions->next_act = new_act;
}
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-15T14:41:42.642Z | Help Write Code | v2 | null | null | null |
A rule is evaluated using the following steps:
Update each of the dependencies. In other words, recursively evaluate each dependency rule.
Compare the last modified time for each of the dependencies to the target.
If the target does not exist, or at least one of the dependencies refers to a file with a last modified time more recent than the target, execute the rule's actions. |
63c648a85f004bf4898cfe7d | 2023-03-15T14:42:22.763Z | Help Write Code | v2 | null | null | null | recursively evaluate each dependency rule. Compare the last modified time for each of the dependencies to the target. If the target does not exist, or at least one of the dependencies refers to a file with a last modified time more recent than the target, execute the rule's actions. |
63c648a85f004bf4898cfe7d | 2023-03-15T15:54:32.307Z | Help Write Code | v2 | null | null | null | The parent process should wait for each child to complete. If the child terminates with a non-zero exit status, the parent should also terminate with a non-zero exit status. This means that pmake will stop when it encounters an error. |
63c648a85f004bf4898cfe7d | 2023-03-15T16:02:30.263Z | Help Write Code | v2 | null | null | null | When pmake is run with the -p option, a child should be created to update each dependency. The parent will create one child process for each dependency and after it has created all of them, the parent will wait for all children to terminate successfully before determining whether it needs to execute the actions.
|
63c648a85f004bf4898cfe7d | 2023-03-15T20:49:12.723Z | Help Write Code | v2 | null | null | null | How to use waitpid give an example |
63c648a85f004bf4898cfe7d | 2023-03-15T21:31:30.706Z | Help Write Code | v2 | null | null | null | the parent will wait for all children to terminate successfully before determining whether it needs to execute the actions. |
63c648a85f004bf4898cfe7d | 2023-03-15T21:32:44.086Z | General Question | v2 | How to use waitpid? | null | null | null |
63c648a85f004bf4898cfe7d | 2023-03-17T18:58:18.978Z | General Question | v2 | How to generate a random number between 0 and 100 using random() | null | null | null |
63c648a85f004bf4898cfe7d | 2023-03-17T18:59:08.313Z | Help Write Code | v2 | null | null | null | Use random() to generate a number between 0 and 100 |
63c648a85f004bf4898cfe7d | 2023-03-17T19:52:39.329Z | Help Write Code | v2 | null | null | null | How to use sigaction? |
63c648a85f004bf4898cfe7d | 2023-03-24T02:54:27.902Z | Help Write Code | v2 | null | null | null | Search the first n characters of buf for a network newline (\r\n).
* Return one plus the index of the '\n' of the first network newline,
* or -1 if no network newline is found. |
63c648a85f004bf4898cfe7d | 2023-03-29T23:10:38.486Z | General Question | v2 | How to use asprintf properly and what should the GNU SOURCE be? | null | null | null |
63c648a85f004bf4898cfe7d | 2023-03-29T23:34:41.493Z | Help Write Code | v2 | null | null | null | I have a list of users and I want to print each user's name in a single line using asprintf() |
63c648a85f004bf4898cfe7d | 2023-03-29T23:37:51.944Z | Help Fix Code | v2 | Return and print a dynamically allocated string that contains the name of every user in a single line. | char *list_users(const User *curr) {
char *string_arr;
char *string;
asprintf(&string_arr, "User List\r\n");
while (curr != NULL) {
asprintf(&string, "\t%s\r\n", curr->name);
curr = curr->next;
}
return string;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-03-30T00:06:19.699Z | Help Write Code | v2 | null | null | null | Return and print a dynamically allocated string that contains the name of every user struct in a single line using asprintf. |
63c648a85f004bf4898cfe7d | 2023-03-30T00:07:07.998Z | Help Write Code | v2 | null | null | null | Return and print a dynamically allocated string that contains the name of every user in a single line using asprintf. |
63c648a85f004bf4898cfe7d | 2023-04-02T04:24:10.802Z | Help Write Code | v2 | null | null | null | Write the friend_server.c code so that you can have one client writing friends commands to the server. When your client connects to the server, ask for and store their name. Then allow them to enter commands. |
63c648a85f004bf4898cfe7d | 2023-04-02T05:30:46.368Z | Help Fix Code | v2 | Connect to the server, ask for and store their name. Then allow them to enter commands. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h> /* gethostname */
#include <sys/socket.h>
#include "friends.h"
#ifndef PORT
#define PORT 58364
#endif
#define BUFSIZE 30
/*
* Initialize a server address associated with the given port.
*/
struct sockaddr_in *init_server_addr(int port) {
struct sockaddr_in *addr = malloc(sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
addr->sin_port = htons(port);
memset(&(addr->sin_zero), 0, 8);
addr->sin_addr.s_addr = INADDR_ANY;
return addr;
}
int set_up_server_socket(struct sockaddr_in *self, int num_queue) {
int soc = socket(AF_INET, SOCK_STREAM, 0);
if (soc < 0) {
perror("socket");
exit(1);
}
int on = 1;
int status = setsockopt(soc, SOL_SOCKET, SO_REUSEADDR,
(const char *) &on, sizeof(on));
if (status < 0) {
perror("setsockopt");
exit(1);
}
if (bind(soc, (struct sockaddr *)self, sizeof(*self)) < 0) {
perror("bind");
exit(1);
}
// Set up a queue in the kernel to hold pending connections.
if (listen(soc, num_queue) < 0) {
perror("listen");
exit(1);
}
return soc;
}
int accept_connection(int listenfd) {
struct sockaddr_in peer;
unsigned int peer_len = sizeof(peer);
peer.sin_family = AF_INET;
int client_socket = accept(listenfd, (struct sockaddr *)&peer, &peer_len);
if (client_socket < 0) {
perror("accept");
return -1;
}
char message[BUFSIZE];
sprintf(message, "What is your name?\r\n");
write(client_socket, message, strlen(message));
return client_socket;
}
int main() {
struct sockaddr_in *self = init_server_addr(PORT);
int listenfd = set_up_server_socket(self, 5);
printf("What is your name?\n");
while (1) {
int fd = accept_connection(listenfd);
if (fd < 0) {
continue;
}
close(fd);
printf("The connection is now closed ...\n");
}
free(self);
close(listenfd);
return 0;
} | null | null |
63c648a85f004bf4898cfe7d | 2023-04-04T02:09:37.653Z | Help Write Code | v2 | null | null | null | When your client connects to the server, ask for and store their name. |
63c648a85f004bf4898cfe7d | 2023-04-05T03:11:12.562Z | Help Write Code | v2 | null | null | null | Design your own client struct to store the information that you need for each client - including a buffer to hold the partial reads, username and their socket fd. Since there is no upper limit to the number of clients, use a linked list data structure to store the client records. |
63c648a95f004bf4898cfe87 | 2023-03-12T20:14:10.005Z | Explain Code | v2 | null |
void print_actions(Action *act) {
while (act != NULL) {
if (act->args == NULL) {
fprintf(stderr, "ERROR: action with NULL args\n");
act = act->next_act;
continue;
}
printf("\t");
int i = 0;
while (act->args[i] != NULL) {
printf("%s ", act->args[i]);
i++;
}
printf("\n");
act = act->next_act;
}
}
void print_rules(Rule *rules) {
Rule *cur = rules;
while (cur != NULL) {
if (cur->dependencies || cur->actions) {
printf("%s : ", cur->target);
Dependency *dep = cur->dependencies;
while (dep != NULL) {
if (dep->rule->target == NULL) {
fprintf(stderr, "ERROR: dependency with NULL rule\n");
}
printf("%s ", dep->rule->target);
dep = dep->next_dep;
}
printf("\n");
print_actions(cur->actions);
}
cur = cur->next_rule;
}
}
| null | null |
63c648a95f004bf4898cfe87 | 2023-03-12T21:01:45.982Z | Help Write Code | v2 | null | null | null | tokenize a string
|
63c648a95f004bf4898cfe87 | 2023-03-12T23:41:49.306Z | Help Write Code | v2 | null | null | null | malloc a member of a struct that is an array of strings
|
63c648a95f004bf4898cfe87 | 2023-03-12T23:50:36.150Z | Help Fix Code | v2 | Creates a node which holds an array of strings that say "hello" | Action* create_action(Rule *node, int count) {
Action *new_action = malloc(sizeof(Action));
new_action->next_act = NULL;
new_action->args = malloc(sizeof(char*) * count);
char hello[MAXLINE] = "hello";
for (int i = 0; i < count; i ++) {
new_action->args[i] = malloc(sizeof(char) * MAXLINE);
strncpy(new_action->args[i], hello, MAXLINE);
new_action->args[i][MAXLINE] = '\0';
}
node->actions = new_action;
return new_action;
} | null | null |
63c648a95f004bf4898cfe87 | 2023-03-12T23:52:31.888Z | Help Fix Code | v2 | Creates a node which holds an array of strings that say "hello" | Action* create_action(Rule *node, int count) {
Action *new_action = malloc(sizeof(Action));
new_action->next_act = NULL;
new_action->args = malloc(sizeof(char*) * count);
char hello[MAXLINE] = "hello";
for (int i = 0; i < count; i ++) {
(new_action->args)[i] = malloc(sizeof(char) * MAXLINE);
strncpy((new_action)->args[i], hello, MAXLINE);
new_action->args[i][MAXLINE - 1] = '\0';
}
node->actions = new_action;
return new_action;
} | null | null |
63c648a95f004bf4898cfe87 | 2023-03-12T23:54:21.602Z | Help Fix Code | v2 | Creates a node which holds an array of strings that say "hello" | Action* create_action(Rule *node, int count) {
Action *new_action = malloc(sizeof(Action));
new_action->next_act = NULL;
new_action->args = malloc(sizeof(char*) * count);
char hello[MAXLINE] = "hello";
for (int i = 0; i < count; i ++) {
(new_action->args)[i] = malloc(sizeof(char) * MAXLINE);
strncpy((new_action)->args[i], hello, MAXLINE);
new_action->args[i][MAXLINE - 1] = '\0';
}
node->actions = new_action;
return new_action;
| null | null |
63c648a95f004bf4898cfe87 | 2023-03-12T23:54:57.184Z | Help Fix Code | v2 | Intended Behavior: Creates a node which holds an array of strings that say "hello" | Action* create_action(Rule *node, int count) {
Action *new_action = malloc(sizeof(Action));
new_action->next_act = NULL;
new_action->args = malloc(sizeof(char*) * count);
char hello[MAXLINE] = "hello";
for (int i = 0; i < count; i ++) {
(new_action->args)[i] = malloc(sizeof(char) * MAXLINE);
strncpy((new_action->args)[i], hello, MAXLINE);
new_action->args[i][MAXLINE - 1] = '\0';
}
node->actions = new_action;
return new_action;
| null | null |
63c648a95f004bf4898cfe87 | 2023-03-12T23:57:26.620Z | Help Write Code | v2 | null | null | null | malloc a struct where a member is an array of strings |
63c648a95f004bf4898cfe87 | 2023-03-13T00:02:30.307Z | Help Fix Code | v2 | and array of strings to a linked list node |
Action* create_action(Rule *node, int count) {
Action *new_action = malloc(sizeof(Action));
new_action->next_act = NULL;
new_action->args = malloc(sizeof(char*) * count);
char hello[MAXLINE] = "hello";
for (int i = 0; i < count; i ++) {
new_action->args[i] = malloc(sizeof(char) * (strlen(hello) + 1));
strncpy(new_action->args[i], hello, (strlen(hello) + 1));
new_action->args[i][strlen(hello)] = '\0';
}
node->actions = new_action;
return new_action;
}
char *dummy[256];
int dummy_count = tokenize(line, dummy);
char *actions[dummy_count];
int action_count = tokenize(line, actions);
create_action(curr, 3); | null | null |
63c648a95f004bf4898cfe87 | 2023-03-13T23:40:24.493Z | Explain Code | v2 | null | int main(int argc, char **argv) {
FILE *fp;
char *filename = "Makefile";
char *target = NULL;
int output = 0;
int parallel = 0;
char opt;
while ((opt = getopt(argc, argv, "f:op")) != -1) {
switch (opt) {
case 'o':
output = 1;
break;
case 'p':
parallel = 1;
break;
case 'f':
filename = optarg;
break;
default:
fprintf(stderr, "Usage: %s [-op] [-f <filename>] [target]\n", argv[0]);
exit(1);
}
}
if (optind < argc) {
target = argv[optind];
}
if ((fp = fopen(filename, "r")) == NULL) {
perror("fopen");
exit(1);
}
Rule *rules = parse_file(fp);
fclose(fp);
if (output) {
print_rules(rules);
}
run_make(target, rules, parallel);
return 0;
} | null | null |
63c648ac5f004bf4898cfea0 | 2023-01-17T22:48:28.132Z | General Question | v1 | create a c function that sums integers in an array | null | null | null |
63c648ac5f004bf4898cfea0 | 2023-01-17T22:50:20.307Z | Question from Code | v1 | why am I not able to get the sum_card function to work? | #include <stdio.h>
#include <stdlib.h>
/*
* This function interprets score_card as an array of pointers with size elements.
* Return the sum of the values pointed to by the elements of score_card.
*/
int sum_card(int score_card, int size) {
// TODO: write the body of sum_card according to its description.
int i;
int sum = 0;
for (i = 0; i < size; i++){
sum = sum + ((score_card[i]));
}
return sum;
}
/*
* NOTE: don't change the main function!
* The command line arguments are a sequence of integers that will be
* used to initialize the array score_card.
*
* Sample usage:
* $ gcc -Wall -std=gnu99 -g -o score_card score_card.c
* $ ./score_card 10 -3 4
* Sum: 11
*/
int main(int argc, char **argv) {
int size = argc - 1;
int *score_card[size];
for (int i = 0; i < size; i++) {
// NOTE: We haven't covered malloc yet, so don't worry about this line.
score_card[i] = malloc(sizeof(int));
*(score_card[i]) = strtol(argv[i + 1], NULL, 10);
}
printf("Sum: %d\n", sum_card(score_card, size));
return 0;
}
| null | null |
63c648ac5f004bf4898cfea0 | 2023-01-17T22:51:35.748Z | Question from Code | v1 | why am I not able to get the sum_card function to work? | #include <stdio.h>
#include <stdlib.h>
/*
* This function interprets score_card as an array of pointers with size elements.
* Return the sum of the values pointed to by the elements of score_card.
*/
int sum_card(int *score_card, int size) {
// TODO: write the body of sum_card according to its description.
int i;
int sum = 0;
for (i = 0; i < size; i++){
sum = sum + ((score_card[i]));
}
return sum;
}
/*
* NOTE: don't change the main function!
* The command line arguments are a sequence of integers that will be
* used to initialize the array score_card.
*
* Sample usage:
* $ gcc -Wall -std=gnu99 -g -o score_card score_card.c
* $ ./score_card 10 -3 4
* Sum: 11
*/
int main(int argc, char **argv) {
int size = argc - 1;
int *score_card[size];
for (int i = 0; i < size; i++) {
// NOTE: We haven't covered malloc yet, so don't worry about this line.
score_card[i] = malloc(sizeof(int));
*(score_card[i]) = strtol(argv[i + 1], NULL, 10);
}
printf("Sum: %d\n", sum_card(score_card, size));
return 0;
}
| null | null |
63c648ac5f004bf4898cfea0 | 2023-01-30T16:02:51.217Z | General Question | v1 | Create a node struct with the following struct members:
- value, an integer
- next, a pointer to another node
Typedef your structure as Node. | null | null | null |
63c648ac5f004bf4898cfea0 | 2023-01-30T16:06:34.571Z | General Question | v1 | Write a loop which traverses a linked list starting at front and prints the value of each node in the list.
Separate each value with a space. | null | null | null |
63c648ac5f004bf4898cfea0 | 2023-02-03T22:29:26.826Z | Question from Code | v1 | 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. The users are stored in a linked list | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME){
return 2; // given name can't fit in the 'name' array
}
User *curr = *user_ptr_add;
while (curr != NULL){
if (strcmp(name, curr->name) == 0){
return 1; // user with the name already exists
}
curr = curr -> next;
}
struct user new_user;
strncpy(new_user.name, name, MAX_NAME - 1);
curr = &new_user;
return 0;
}
| null | null |
63c648ac5f004bf4898cfea0 | 2023-02-03T22:30:28.518Z | Question from Code | v1 | is there anything wrong with my code? | int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME){
return 2; // given name can't fit in the 'name' array
}
User *curr = *user_ptr_add;
while (curr != NULL){
if (strcmp(name, curr->name) == 0){
return 1; // user with the name already exists
}
curr = curr -> next;
}
struct user new_user;
strncpy(new_user.name, name, MAX_NAME - 1);
curr = &new_user;
return 0;
}
| null | null |
63c648ac5f004bf4898cfea0 | 2023-02-03T22:39:08.740Z | Question from Code | v1 | can you make sure that I'm mutating the linked list structure when I run create_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;
int create_user(const char *name, User **user_ptr_add) {
if (strlen(name) >= MAX_NAME){
return 2; // given name can't fit in the 'name' array
}
User *curr = *user_ptr_add;
while (curr != NULL){
if (strcmp(name, curr->name) == 0){
return 1; // user with the name already exists
}
curr = curr -> next;
}
struct user new_user;
strncpy(new_user.name, name, MAX_NAME - 1);
curr = &new_user;
return 0;
}
| null | null |
63c648ac5f004bf4898cfea0 | 2023-02-03T22:40:01.627Z | Question from Code | v1 | Modify this code to make sure that create_user mutates the linked list structure |
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) {
if (strlen(name) >= MAX_NAME){
return 2; // given name can't fit in the 'name' array
}
User *curr = *user_ptr_add;
while (curr != NULL){
if (strcmp(name, curr->name) == 0){
return 1; // user with the name already exists
}
curr = curr -> next;
}
struct user new_user;
strncpy(new_user.name, name, MAX_NAME - 1);
curr = &new_user;
return 0;
}
| null | null |
63c648ac5f004bf4898cfea0 | 2023-02-07T05:48:11.217Z | General Question | v1 | When you execute the following command
gcc -S my_prog.c
and it runs without errors or warnings, what is the name of the file that is produced? | null | null | null |
63c648ac5f004bf4898cfea0 | 2023-02-07T05:48:45.227Z | General Question | v1 | When you execute the following command
gcc fiddle.c
and it runs without errors or warnings, what is the name of the file that is produced? | null | null | null |
63c648ac5f004bf4898cfea0 | 2023-02-07T06:03:40.060Z | Question from Code | v1 | What is rm -f *.o print_ptree? | Consider the following Makefile
FLAGS = -Wall -Werror -std=c99
DEPENDENCIES = ptree.h
all: print_ptree
print_ptree: print_ptree.o ptree.o
gcc ${FLAGS} -o $@ $^
%.o: %.c ${DEPENDENCIES}
gcc ${FLAGS} -c $<
clean:
rm -f *.o print_ptree | null | null |
63c648ac5f004bf4898cfea0 | 2023-02-07T06:04:32.915Z | Question from Code | v1 |
What is FLAGS? | Consider the following Makefile
FLAGS = -Wall -Werror -std=c99
DEPENDENCIES = ptree.h
all: print_ptree
print_ptree: print_ptree.o ptree.o
gcc ${FLAGS} -o $@ $^
%.o: %.c ${DEPENDENCIES}
gcc ${FLAGS} -c $<
clean:
rm -f *.o print_ptree
| null | null |
63c648ac5f004bf4898cfea0 | 2023-02-07T06:05:11.528Z | Question from Code | v1 | What is print_ptree? | Consider the following Makefile
FLAGS = -Wall -Werror -std=c99
DEPENDENCIES = ptree.h
all: print_ptree
print_ptree: print_ptree.o ptree.o
gcc ${FLAGS} -o $@ $^
%.o: %.c ${DEPENDENCIES}
gcc ${FLAGS} -c $<
clean:
rm -f *.o print_ptree | null | null |
63c648ac5f004bf4898cfea0 | 2023-02-10T06:02:34.053Z | General Question | v1 | How can I allocate space in dynamic memory for a 2 dimensional array that contains pointers | null | null | null |
63c648ac5f004bf4898cfea0 | 2023-02-13T15:48:28.534Z | Question from Code | v1 |
What is the line to compile it into an executable named a.out that it will print the value 5 to stdout? (You do not need to include the options to display warnings, build the symbol table for the debugger or select the C standard.) | #include <stdio.h>
int main() {
#ifdef MACRO
printf("%d\n", MACRO);
#endif
return 0;
} | null | null |
63c648ac5f004bf4898cfea0 | 2023-02-13T15:50:54.063Z | General Question | v1 | suppose we have the following line at the top of our program
#define MAXNAME = 32;
and then the declaration
char name[MAXNAME];
in the program. What will this declaration line become after the program has passed
through the C pre-processor? | null | null | null |
63c648ac5f004bf4898cfea0 | 2023-02-14T02:20:18.146Z | General Question | v1 |
Consider the following function:
char * my_func(char * filename) {
// contents not shown
}
Which of the following lines would compile correctly following this function?
char * x = my_func;
char * x = my_func("blah.txt");
char * (*x) (char *) = my_func;
char * (*x) (char *) = my_func("blah.txt");
char x[10] = my_func("blah.txt");
| null | null | null |
63c648ac5f004bf4898cfea0 | 2023-03-13T01:20:52.114Z | 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 ");
// POSITION A
struct sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act, NULL);
// POSITION B
x += 2;
// POSITION C
fprintf(stderr, "outside %d", x);
return 0;
}
| null | null |
63c648ac5f004bf4898cfea0 | 2023-03-28T06:37:49.055Z | General Question | v2 |
d=31
Write a sh command involving variable d to print the following to standard out:
March has 31 days | null | null | null |
63c648ac5f004bf4898cfea0 | 2023-03-28T06:48:21.251Z | General Question | v2 |
Variable x has been assigned a digit between 1 and 10. Write a shell command to calculate x minus 1 and display the result to standard output.
| null | null | null |
63c648ac5f004bf4898cfea5 | 2023-01-22T19:02:17.662Z | Help Fix Code | v1 | null | /*
* This function compares two 9-element char arrays that correspond to file
* permissions.
* If the file has the needed permissions it returns 0, otherwise it returns 1.
*/
int check_permissions(char *file_perm, char *reqd_perm) {
for (int i = 0; i < 10; i++) {
if (reqd_perm[i] != "-" && reqd_perm[i] != file_perm[i]) {
printf("missing permission in index %d\n", i);
return 1;
}
}
printf("all permissions checked");
return 0;
} | Compare two 9-element char arrays | null |
63c648ac5f004bf4898cfea5 | 2023-01-22T19:05:02.950Z | Help Fix Code | v1 | null | /*
* This function compares two 9-element char arrays that correspond to file
* permissions.
* If the file has the needed permissions it returns 0, otherwise it returns 1.
*/
int check_permissions(char *file_perm, char *reqd_perm) {
for (int i = 0; i < 10; i++) {
if (reqd_perm[i] != "-" && reqd_perm[i] != file_perm[i]) {
printf("missing permission in index %d\n", i);
return 1;
}
}
printf("all permissions checked");
return 0;
} | Compare two arrays of 9 characters, but only where reqd_perm[i] != "-". | null |
63c648ad5f004bf4898cfeaa | 2023-02-12T23:51:47.960Z | General Question | v1 | How do I change the value of a **pointer
| null | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-12T23:53:31.665Z | Question from Code | v1 | In the if (temp == NULL) case, how do I assign user to the temp | int create_user(const char *name, User **user_ptr_add) {
User user;
if(strlen(name) > sizeof(user.name) - 1){
return 2;
}
strcpy(user.name, name);
User *temp = *user_ptr_add;
if (temp == NULL){
*temp = user;
return 0;
}
while (temp->next != NULL){
if(strcmp(temp->name, name) == 0){
return 1;
}
temp = temp->next;
}
temp->next = &user;
return 0;
} | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-12T23:54:32.968Z | Question from Code | v1 | Why is user not being assigned to temp properly | int create_user(const char *name, User **user_ptr_add) {
User user;
if(strlen(name) > sizeof(user.name) - 1){
return 2;
}
strcpy(user.name, name);
User *temp = *user_ptr_add;
temp = malloc(sizeof(User));
if (temp == NULL){
*temp = user;
return 0;
}
while (temp->next != NULL){
if(strcmp(temp->name, name) == 0){
return 1;
}
temp = temp->next;
}
temp->next = &user;
return 0;
} | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-12T23:57:04.866Z | Question from Code | v1 | Why is the value of user not being stored in user_ptr_add properly | int create_user(const char *name, User **user_ptr_add) {
User user;
if(strlen(name) > sizeof(user.name) - 1){
return 2;
}
strcpy(user.name, name);
*user_ptr_add = malloc(sizeof(User));
User *temp = *user_ptr_add;
if (temp == NULL){
temp[0] = user;
return 0;
}
while (temp->next != NULL){
if(strcmp(temp->name, name) == 0){
return 1;
}
temp = temp->next;
}
temp->next = &user;
return 0;
} | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T00:18:13.929Z | Question from Code | v1 | why can I not cast const to head | User *find_user(const char *name, const User *head) {
while(head != NULL){
if(strcmp(head->name, name) == 0){
return (const User *) head;
}
}
return NULL;
} | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T00:19:00.479Z | Question from Code | v1 | How to prevent return discards ‘const’ qualifier from pointer target type | User *find_user(const char *name, const User *head) {
while(head != NULL){
if(strcmp(head->name, name) == 0){
return head;
}
}
return NULL;
} | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T00:28:12.390Z | General Question | v1 | is the mode for fopen an optional argument | null | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T02:22:42.340Z | General Question | v1 | How to printf type time_t | null | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T02:30:08.942Z | General Question | v1 | how do I check the number of elements in an array | null | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T02:52:46.919Z | General Question | v1 | how do I read characters from an ascii file | null | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T04:18:28.363Z | General Question | v1 | How do I get the time | null | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T04:47:34.319Z | General Question | v1 | If I have a time_t * variable how do I store the time. | null | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T04:51:13.601Z | General Question | v1 | How do I use ctime
| null | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T05:00:04.403Z | Question from Code | v1 | HOw do I store the time in the date attribute of a post | typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post; | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T05:06:36.778Z | General Question | v1 | How to set the value of one char* to another char* | null | null | null |
63c648ad5f004bf4898cfeaa | 2023-02-13T05:09:00.390Z | 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) {
Post *post = malloc(sizeof(post));
strcpy(post->contents, contents);
} | assign contents to the contents attribute in a post | null |
63c648ae5f004bf4898cfeb4 | 2023-01-18T06:25:25.372Z | General Question | v1 | Should we always include the function prototype? | null | null | null |
63c648ae5f004bf4898cfeb4 | 2023-01-18T06:26:43.553Z | General Question | v1 | Should returning error or not (1 or 0) be explicitly written, or can we return a variable that stores either 0 or 1 | null | null | null |