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
⌀ |
---|---|---|---|---|---|---|---|
63c648125f004bf4898cf932 | 2023-03-28T03:15:51.557Z | General Question | v2 | can i use % string formating in a write() call? | null | null | null |
63c648125f004bf4898cf932 | 2023-03-28T22:15:12.275Z | General Question | v2 | what is the first argument passed to select()? | null | null | null |
63c648125f004bf4898cf932 | 2023-04-06T13:46:40.893Z | General Question | v2 | how to check if a pointer points to NULL? | null | null | null |
63c648125f004bf4898cf932 | 2023-04-06T13:51:53.191Z | General Question | v2 | how to malloc an int for a struct | null | null | null |
63c648125f004bf4898cf932 | 2023-04-06T14:01:16.077Z | Question from Code | v2 | will this code safely allocate an int on the heap? | int *ptr = malloc(sizeof(int));
int num = 42;
*ptr = num; | null | null |
63c648125f004bf4898cf932 | 2023-04-06T15:42:02.506Z | General Question | v2 | how to use write to write to a buffer string? | null | null | null |
63c648125f004bf4898cf932 | 2023-04-06T17:47:35.856Z | General Question | v2 | when do you have to close a fd? | null | null | null |
63c648125f004bf4898cf932 | 2023-04-06T18:17:54.004Z | Question from Code | v2 | does this properly set buf to an empty string? | char buf[5];
buf = {'/0'}; | null | null |
63c648135f004bf4898cf937 | 2023-01-31T03:50:51.950Z | Question from Code | v1 | why is there a compilation error | void update_contact(struct *contact friend, char *new_name, int new_number, char *new_address) {
strcpy(friend.name, new_name);
friend.phone_number = new_number;
strcpy(friend.address, new_address);
} | null | null |
63c648135f004bf4898cf937 | 2023-01-31T03:54:12.879Z | Help Fix Code | v1 | null | void update_contact(struct *contact friend, char *new_name, int new_number, char *new_address) {
strcpy(friend.name, new_name);
friend.phone_number = new_number;
strcpy(friend.address, new_address);
} | update struct contact
| null |
63c648135f004bf4898cf937 | 2023-01-31T04:37:29.685Z | Question from Code | v1 | why is there a compilation error | void update_contact(struct *contact friend, int new_name, int new_number, char *new_address) {
strcpy(friend->name, new_name);
friend->phone_number = new_number;
strcpy(friend->address, new_address);
} | null | null |
63c648135f004bf4898cf937 | 2023-01-31T04:41:18.233Z | Question from Code | v1 | compilation erroR? | void update_contact(struct *contact friend, char* new_name, int new_number, char *new_address) {
strcpy(friend->name, new_name);
friend->phone_number = new_number;
strcpy(friend->address, new_address);
} | null | null |
63c648135f004bf4898cf937 | 2023-04-21T20:30:16.524Z | Question from Code | v2 | Why is it that if I sigint at position A, the process is terminated? I didn't call quit in the handler function | int x = 5;
void handler(int sig) {
x += 3;
fprintf(stderr, "inside %d ", x);
}
int main() {
fprintf(stderr, "start ");
struct sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act, NULL);
x += 2;
fprintf(stderr, "outside %d", x);
return 0;
} | null | null |
63c648135f004bf4898cf937 | 2023-04-21T20:40:56.378Z | General Question | v2 | A signal handling function that you write must always have the same signature.Why is this true?
| null | null | null |
63c648165f004bf4898cf950 | 2023-02-12T21:37:00.055Z | Help Fix Code | v1 | null | #include "friends.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
const int MAX_PFP = 40;
/*
* 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) {
User *new = malloc(sizeof(User));
User *curr = *user_ptr_add;
User *prev = NULL;
if (new < 0){
return -1;
}
if(strlen(name) >= MAX_NAME){
return 2;
}
printf("%s\n", name);
while(curr != NULL){
if(strcmp(curr->name, name) == 0){
return 1;
}
prev = curr;
curr = curr->next;
}
strncpy(new->name, name, MAX_NAME);
printf("%s\n", new->name);
prev->next = new;
return 0;
} | Create a new user with the given name. Insert it at the tail of the list
* of users whose head is pointed to by *user_ptr_add. | null |
63c648165f004bf4898cf950 | 2023-02-13T19:42:33.882Z | Help Fix Code | v1 | null | int delete_user(const char *name, User **user_ptr_del) {
User* curr = *user_ptr_del;
User* prev = NULL;
int found = 0;
// iterate through the list
while (curr != NULL){
// check if the curr is pointing to the user to be deleted
if(strcmp(curr->name, name) == 0){
// check if the user to be deleted is the first user
if (curr == *user_ptr_del){
*user_ptr_del = curr->next;
}
else{
prev->next = curr->next;
}
found = 1;
free(curr);
break;
}
// check if curr is friends with the user to be deleted
else{
for (int i = 0; i < MAX_FRIENDS; i++){
if (curr->friends[i] == NULL){
break;
}
if (strcmp(curr->friends[i]->name, name) == 0){
curr->friends[i] = NULL;
}
}
curr = curr->next;
}
}
if (found == 0){
return 1;
}
return 0;
} | /*
* Make a new post from 'author' to the 'target' user,
* containing the given contents, IF the users are friends.
*
* Insert the new post at the *front* of the user's list of posts.
*
* 'contents' is a pointer to heap-allocated memory - you do not need
* to allocate more memory to store the contents of the post.
*
* Return:
* - 0 on success
* - 1 if users exist but are not friends
* - 2 if either User pointer is NULL
*/ | null |
63c648165f004bf4898cf950 | 2023-02-13T20:10:47.507Z | Help Fix Code | v1 | null | int make_post(const User *author, User *target, char *contents) {
// check if users exist
if (author == NULL || target == NULL){
return 2;
}
// check if they are friends
int isFriend = 0;
for (int i = 0; i < MAX_FRIENDS; i++){
if (author->friends[i] == target){
isFriend = 1;
break;
}
}
if (isFriend == 0){
return 1;
}
// create new post
Post* newPost = malloc(sizeof(Post));
newPost->contents = contents;
strncpy(newPost->author, author->name, MAX_NAME);
time_t now;
time(&now);
newPost->date = &now;
// insert the new post to the front of the list for the target user
newPost->next = target->first_post;
target->first_post = newPost;
return 0;
}
| Set the time of the post to the current time using time() | null |
63c648165f004bf4898cf950 | 2023-02-13T20:13:01.385Z | Help Fix Code | v1 | null | int make_post(const User *author, User *target, char *contents) {
// check if users exist
if (author == NULL || target == NULL){
return 2;
}
// check if they are friends
int isFriend = 0;
for (int i = 0; i < MAX_FRIENDS; i++){
if (author->friends[i] == target){
isFriend = 1;
break;
}
}
if (isFriend == 0){
return 1;
}
// create new post
Post* newPost = malloc(sizeof(Post));
newPost->contents = contents;
strncpy(newPost->author, author->name, MAX_NAME);
time_t now;
time(&now);
newPost->date = &now;
// insert the new post to the front of the list for the target user
newPost->next = target->first_post;
target->first_post = newPost;
return 0;
}
| /*
* Make a new post from 'author' to the 'target' user,
* containing the given contents, IF the users are friends.
*
* Insert the new post at the *front* of the user's list of posts.
*
* 'contents' is a pointer to heap-allocated memory - you do not need
* to allocate more memory to store the contents of the post.
*
* Return:
* - 0 on success
* - 1 if users exist but are not friends
* - 2 if either User pointer is NULL
*/ | null |
63c648165f004bf4898cf950 | 2023-02-13T20:24:40.738Z | Help Fix Code | v1 | null | int print_user(const User *user) {
if (user == NULL){
return 1;
}
printf("------------------------------------------\n");
printf("Posts:\n");
// print posts
Post* currPost = user->first_post;
while (currPost != NULL){
printf("From: %s\n", currPost->author);
printf("Date: %s\n", ctime(currPost->date));
printf("%s\n", currPost->contents);
currPost = currPost->next;
return 0;
}
| Print user profile and any associated posts. However the time is not printed properly. | null |
63c648165f004bf4898cf950 | 2023-02-13T20:28:54.100Z | Question from Code | v1 | the time is not printed properly from line 71 | int make_post(const User *author, User *target, char *contents) {
// check if users exist
if (author == NULL || target == NULL){
return 2;
}
// check if they are friends
int isFriend = 0;
for (int i = 0; i < MAX_FRIENDS; i++){
if (author->friends[i] == target){
isFriend = 1;
break;
}
}
if (isFriend == 0){
return 1;
}
// create new post
Post* newPost = malloc(sizeof(Post));
newPost->contents = contents;
strncpy(newPost->author, author->name, MAX_NAME);
// allocate and set time
newPost->date = (time_t*)malloc(sizeof(time_t));
time_t now = time(NULL);
time(&now);
newPost->date = &now;
//printf("%s\n", ctime(newPost->date));
// insert the new post to the front of the list for the target user
newPost->next = target->first_post;
target->first_post = newPost;
return 0;
}
int print_user(const User *user) {
if (user == NULL){
return 1;
}
// print profile pic
char currChar;
FILE *fp = fopen(user->profile_pic, "r");
if (fp != NULL){
while((fscanf(fp, "%c", &currChar)) != EOF){
printf("%c", currChar);
}
printf("\n");
fclose(fp);
}
printf("Name: %s\n", user->name);
printf("------------------------------------------\n");
//print friends
printf("Friends:\n");
for (int i = 0; i < MAX_FRIENDS; i++){
if (user->friends[i] != NULL){
printf("%s\n", user->friends[i]->name);
}
}
printf("------------------------------------------\n");
printf("Posts:\n");
// print posts
Post* currPost = user->first_post;
while (currPost != NULL){
printf("From: %s\n", currPost->author);
printf("Date: %s\n", ctime(currPost->date));
printf("%s\n", currPost->contents);
currPost = currPost->next;
// padding prints
if (currPost != NULL){
printf("\n");
printf("===\n");
printf("\n");
}
}
printf("------------------------------------------\n");
return 0;
}
| null | null |
63c648165f004bf4898cf950 | 2023-02-14T22:11:05.039Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
User* curr1 = find_user(name1, head);
User* curr2 = find_user(name2, head);
// check if user exists
if (curr1 == NULL || curr2 == NULL){
return 4;
}
// check if the same user is passed in twice
if (curr1 == curr2){
return 3;
}
// check for number of friends for each user
int count1 = 0;
for(int i = 0; i < MAX_FRIENDS; i++){
if (curr1->friends[i] != NULL){
count1 += 1;
// check if the two users are already friends
if (curr1->friends[i] == curr2)
{
return 1;
}
}
}
int count2 = 0;
for(int i = 0; i<MAX_FRIENDS;i++){
if (curr2->friends[i] != NULL){
count2 += 1;
// check if the two users are already friends
if (curr2->friends[i] == curr1)
{
return 1;
}
}
}
if (count1 >= MAX_FRIENDS || count2 >= MAX_FRIENDS){
return 2;
}
int i1 = 0;
int i2 = 0;
while (i1 < MAX_FRIENDS || i2 < MAX_FRIENDS){
if (curr1->friends[i1] != NULL){
i1++;
}
else{
curr1->friends[i1] = curr2;
}
if (curr2->friends[i2] != NULL){
i2++;
}
else{
curr2->friends[i2] = curr1;
}
if (curr1->friends[i1] != NULL && curr2->friends[i2] != NULL){
break;
}
}
return 0;
} | /*
* Make two users friends with each other. This is symmetric - a pointer to
* each user must be stored in the 'friends' array of the other.
*
* New friends must be added in the first empty spot in the 'friends' array.
*
* Return:
* - 0 on success.
* - 1 if the two users are already friends.
* - 2 if the users are not already friends, but at least one already has
* MAX_FRIENDS friends.
* - 3 if the same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/ | null |
63c648165f004bf4898cf950 | 2023-03-06T03:53:30.260Z | Help Fix Code | v1 | null | Rule *parse_file(FILE *fp) {
char buffer[MAXLINE+1];
Rule *curr_rule = NULL;
RuleLL *head = malloc(sizeof(RuleLL));
// Read each line until the EOF
while(fgets(buffer, MAXLINE, fp) != NULL) {
if (!is_comment_or_empty(buffer)) {
// Target line
if(buffer[0] != '\t') {
char delim[] = " ";
// Find if the rule already exists in head
char* token = strtok(buffer, delim);
curr_rule = find_rule(head, token);
// Else if the current Target is not in the head_rule, create a new rule
if (curr_rule == NULL){
curr_rule = malloc(sizeof(Rule));
curr_rule->actions = NULL;
curr_rule->target = malloc(strlen(token) + 1);
strcpy(curr_rule->target, token);
insert_rule(head, curr_rule);
}
// Skip the colon
token = strtok(NULL, delim);
token = strtok(NULL, delim);
// Add dependencies to the current rule
while(token != NULL) {
Dependency *new_dep = malloc(sizeof(Dependency));
// Find the rule that matches the dependency in head_rule
Rule *dep_rule = find_rule(head, token);
// If the dependency rule is found
if (dep_rule != NULL) {
new_dep->rule = dep_rule;
}
// Else, then create a new rule for the dependency
else{
new_dep->rule = malloc(sizeof(Rule));
// if it has trailing \n character, don't include it
/* if (token[strlen(token)-1] == '\n') {
token[strlen(token)-1] = '\0';
} */
if (token[strlen(token)-1] == '\n') {
new_dep->rule->target = malloc(strlen(token));
strcpy(new_dep->rule->target, token - 1);
new_dep->rule->target[strlen(token)-1] = '\0';
}
else{
new_dep->rule->target = malloc(strlen(token) + 1);
strcpy(new_dep->rule->target, token);
}
insert_rule(head, new_dep->rule);
}
// Add the dependency to the current rule
insert_dependency(curr_rule, new_dep);
token = strtok(NULL, delim);
}
}
// Action line
else {
//printf("%s", buffer);
int num_tokens = 0;
char delim[] = " ";
char* token = strtok(buffer, delim);
while(token != NULL) {
num_tokens++;
token = strtok(NULL, delim);
}
// Make new token
char *new_token = strtok(buffer, delim);
Action *new_act = malloc(sizeof(Action));
new_act->args = malloc(sizeof(char*)*(num_tokens+1));
int i = 0;
while(new_token != NULL) {
if(new_token[0] == '\t'){
new_token = new_token + 1;
}
new_act->args[i] = malloc(strlen(new_token) + 1);
strcpy(new_act->args[i], new_token);
printf("%s\n", new_token);
i++;
new_token = strtok(NULL, delim);
}
new_act->args[i] = NULL;
// Add the action to the current rule
insert_action(curr_rule, new_act);
}
}
}
if (head) {
return head->rule;
}
return NULL;
}
| When inserting new dependency, if it has trailing '\n' it shouldn't include it as shown in line 50. However, it fails for some cases to filter out '\n' character. | null |
63c648165f004bf4898cf950 | 2023-03-06T04:07:18.831Z | Help Fix Code | v1 | null | int num_tokens = 0;
char delim[] = " ";
char* token = strtok(buffer, delim);
while(token != NULL) {
num_tokens++;
token = strtok(NULL, delim);
}
// Make new token
char *new_token = strtok(buffer, delim);
Action *new_act = malloc(sizeof(Action));
new_act->args = malloc(sizeof(char*)*(num_tokens+1));
int i = 0;
while(new_token != NULL) {
if(new_token[0] == '\t'){
new_token = new_token + 1;
}
new_act->args[i] = malloc(strlen(new_token) + 1);
strcpy(new_act->args[i], new_token);
//printf("%s\n", new_token);
i++;
new_token = strtok(NULL, delim);
}
new_act->args[i] = NULL;
// Add the action to the current rule
insert_action(curr_rule, new_act); | each string token is not being iterated properly | null |
63c648165f004bf4898cf950 | 2023-03-08T04:11:10.378Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define MAXLINE 256
#define SUCCESS "Password verified\n"
#define INVALID "Invalid password\n"
#define NO_USER "No such user\n"
int main(void) {
char user_id[MAXLINE];
char password[MAXLINE];
/* The user will type in a user name on one line followed by a password
on the next.
DO NOT add any prompts. The only output of this program will be one
of the messages defined above.
Please read the comments in validate carefully
*/
if(fgets(user_id, MAXLINE, stdin) == NULL) {
perror("fgets");
exit(1);
}
if(fgets(password, MAXLINE, stdin) == NULL) {
perror("fgets");
exit(1);
}
int fd[2];
if(pipe(fd) == -1) {
perror("pipe");
exit(1);
}
int read_end = fd[0];
int write_end = fd[1];
pid_t pid = fork();
//child process
if (pid == 0){
wait(0);
close(write_end);
dup2(read_end, STDIN_FILENO);
close(read_end);
execl("./validate", "validate", NULL);
}
// parent process
else if (pid > 0){
close(read_end);
write(write_end, user_id, strlen(user_id));
write(write_end, password, strlen(password));
close(write_end);
int status;
wait(&status);
if (WIFEXITED(status)){
int exit_status = WEXITSTATUS(status);
if (exit_status == 0){
printf("%s\n", SUCCESS);
}
else if (exit_status == 1){
printf("%s\n", INVALID);
}
else if (exit_status == 2){
printf("%s\n", NO_USER);
}
}
else{
perror("wait");
exit(1);
}
}
else{
perror("fork");
exit(1);
}
return 0;
}
| in line 50, when validate needs to read from stdin, but it can't read from it. | null |
63c648165f004bf4898cf950 | 2023-03-08T04:12:22.730Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define MAXLINE 256
#define SUCCESS "Password verified\n"
#define INVALID "Invalid password\n"
#define NO_USER "No such user\n"
int main(void) {
char user_id[MAXLINE];
char password[MAXLINE];
/* The user will type in a user name on one line followed by a password
on the next.
DO NOT add any prompts. The only output of this program will be one
of the messages defined above.
Please read the comments in validate carefully
*/
if(fgets(user_id, MAXLINE, stdin) == NULL) {
perror("fgets");
exit(1);
}
if(fgets(password, MAXLINE, stdin) == NULL) {
perror("fgets");
exit(1);
}
int fd[2];
if(pipe(fd) == -1) {
perror("pipe");
exit(1);
}
int read_end = fd[0];
int write_end = fd[1];
pid_t pid = fork();
//child process
if (pid == 0){
wait(0);
close(write_end);
dup2(read_end, STDIN_FILENO);
close(read_end);
execl("./validate", "validate", NULL);
}
// parent process
else if (pid > 0){
close(read_end);
write(write_end, user_id, strlen(user_id));
write(write_end, password, strlen(password));
close(write_end);
int status;
wait(&status);
if (WIFEXITED(status)){
int exit_status = WEXITSTATUS(status);
if (exit_status == 0){
printf("%s\n", SUCCESS);
}
else if (exit_status == 1){
printf("%s\n", INVALID);
}
else if (exit_status == 2){
printf("%s\n", NO_USER);
}
}
else{
perror("wait");
exit(1);
}
}
else{
perror("fork");
exit(1);
}
return 0;
}
| in line 50, the program run from execl cannot read from stdin. | null |
63c648165f004bf4898cf950 | 2023-03-08T04:13:14.704Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define MAXLINE 256
#define SUCCESS "Password verified\n"
#define INVALID "Invalid password\n"
#define NO_USER "No such user\n"
int main(void) {
char user_id[MAXLINE];
char password[MAXLINE];
/* The user will type in a user name on one line followed by a password
on the next.
DO NOT add any prompts. The only output of this program will be one
of the messages defined above.
Please read the comments in validate carefully
*/
if(fgets(user_id, MAXLINE, stdin) == NULL) {
perror("fgets");
exit(1);
}
if(fgets(password, MAXLINE, stdin) == NULL) {
perror("fgets");
exit(1);
}
int fd[2];
if(pipe(fd) == -1) {
perror("pipe");
exit(1);
}
int read_end = fd[0];
int write_end = fd[1];
pid_t pid = fork();
//child process
if (pid == 0){
close(write_end);
dup2(read_end, STDIN_FILENO);
close(read_end);
execl("./validate", "validate", NULL);
}
// parent process
else if (pid > 0){
close(read_end);
write(write_end, user_id, strlen(user_id));
write(write_end, password, strlen(password));
close(write_end);
int status;
wait(&status);
if (WIFEXITED(status)){
int exit_status = WEXITSTATUS(status);
if (exit_status == 0){
printf("%s\n", SUCCESS);
}
else if (exit_status == 1){
printf("%s\n", INVALID);
}
else if (exit_status == 2){
printf("%s\n", NO_USER);
}
}
else{
perror("wait");
exit(1);
}
}
else{
perror("fork");
exit(1);
}
return 0;
}
| the program run from excl in line 49 cannot read from stdin. | null |
63c648165f004bf4898cf950 | 2023-03-11T01:06:37.746Z | Help Fix Code | v2 | The program works, but curr_act prints twice in line 65-70. | void evaluate_part2(Rule *head, Rule *rule){
// 1. Update each of the dependencies. In other words, recursively evaluate each dependency rule.
Dependency *curr_dep = rule->dependencies;
while (curr_dep != NULL) {
evaluate_part2(head, curr_dep->rule);
curr_dep = curr_dep->next_dep;
}
// 2. Compare the last modified time for each of the dependencies to the target.
// If the target does not have any dependencies, execute the rule's actions
while (curr_dep2 != NULL) {
struct stat dep_stat;
int dep_exist = stat(curr_dep2->rule->target, &dep_stat);
// 3. 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.
struct timespec dep_time = dep_stat.st_mtim;
if (target_exist != 0 || dep_exist != 0 || dep_time.tv_sec > target_time.tv_sec || \
(dep_time.tv_sec == target_time.tv_sec && dep_time.tv_nsec > target_time.tv_nsec)) {
Action *curr_act = rule->actions;
while (curr_act != NULL) {
int visited = 0;
// Execute the rule's actions
pid_t pid = fork();
if (pid == 0) {
// Print the current action line
int i = 0;
if (visited == 0) {
while (curr_act->args[i] != NULL) {
printf("%s ", curr_act->args[i]);
i++;
}
printf("\n");
visited = 1;
}
execvp(curr_act->args[0], curr_act->args);
fprintf(stderr, "Error: execvp failed\n");
exit(1);
}
} else {
int status;
waitpid(pid, &status, 0);
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
fprintf(stderr, "Error: child process failed\n");
exit(1);
}
}
curr_act = curr_act->next_act;
}
}
curr_dep2 = curr_dep2->next_dep;
}
} | null | null |
63c648165f004bf4898cf950 | 2023-03-11T01:31:18.548Z | Help Fix Code | v2 | it segments error at line 13 | typedef struct rl{
Rule *rule;
struct rl *next_node;
int visited;
} RuleLL;
// ==================== Helper Functions ====================
// Check if the rule is already in the rule linked list
int is_in_ruleLL(RuleLL *head, Rule *rule) {
RuleLL *curr = head;
while (curr != NULL) {
if (curr->rule == rule) {
return 1;
}
curr = curr->next_node;
}
return 0;
}
| null | null |
63c648165f004bf4898cf950 | 2023-03-29T20:51:15.090Z | Help Fix Code | v2 | function returns dynamically allocated string that contains the list of users stored in linked list curr. I get the error that list is used unitialized | char* list_users(const User *curr) {
// First loop until curr is NULL to find the total number of chars to allocate
int list_len = 0;
while (curr != NULL) {
list_len += strlen(curr->name) + 2; // +2 for tab and new line
curr = curr->next;
}
list_len += 1; // +1 for null terminator
list_len += 10; // +10 for "User List\n"
char *list = malloc(list_len * sizeof(char));
strcat(list, "User List\n");
while (curr != NULL) {
strcat(list, "\t");
strcat(list, curr->name);
strcat(list, "\n");
curr = curr->next;
}
return list;
} | null | null |
63c648165f004bf4898cf955 | 2023-03-12T01:36:43.498Z | Help Fix Code | v2 | This code recursively evaluates rules by comparing the most recent modification time. | void evaluate_rule(Rule *rule, struct stat *parent_stat){
// given some conditions, execute action of the rule (compares dependencies)
struct stat rule_stat;
stat(rule->target, &rule_stat);
Dependency *cur_dep = rule->dependencies;
if(cur_dep != NULL){
// recursively call on dependency rules
while(cur_dep != NULL){
evaluate_rule(cur_dep->rule, &rule_stat);
cur_dep = cur_dep->next_dep;
}
}
printf("%s %s", "Cur rule: ", rule->target);
if(rule->dependencies == NULL){
execute_action(rule->target, rule->actions);
}
// retrieve modified time
if(&rule_stat.st_mtim == NULL){
printf("%s\n", " has null mod time");
} else {
printf("%s %ld\n", ", mod_time: ", rule_stat.st_mtim.tv_sec);
}
if(parent_stat != NULL){
if(rule_stat.st_mtim.tv_sec > parent_stat->st_mtim.tv_sec){
execute_action(rule->target, rule->actions);
} else if(rule_stat.st_mtim.tv_sec == parent_stat->st_mtim.tv_sec){
if(rule_stat.st_mtim.tv_nsec > parent_stat->st_mtim.tv_nsec){
execute_action(rule->target, rule->actions);
}
}
} else {
execute_action(rule->target, rule->actions);
}
} | null | null |
63c648165f004bf4898cf955 | 2023-03-12T01:41:14.486Z | Help Write Code | v2 | null | null | null | I want to write code that recursively calls the function through a linked list structure with each node being its own linked list. For each function call, I want to call a helper function: evaluate(Node). |
63c648165f004bf4898cf955 | 2023-03-12T01:45:01.101Z | Help Write Code | v2 | null | null | null | Write function: Evaluate. This function traverses a linked list with linked list nodes and recursively calls the function. The base case prints the value at the node. |
63c648195f004bf4898cf969 | 2023-01-17T19:23:51.650Z | General Question | v1 | How do I print an emoji to stdout? | null | null | null |
63c648195f004bf4898cf969 | 2023-01-17T19:26:27.004Z | Help Write Code | v1 | null | null | null | Implement a max-heap data structure |
63c648195f004bf4898cf969 | 2023-01-20T03:17:46.969Z | General Question | v1 | How do you read a string from stdin using scanf? | null | null | null |
63c648195f004bf4898cf969 | 2023-01-20T03:27:58.442Z | General Question | v1 | What does %10s do? | null | null | null |
63c648195f004bf4898cf969 | 2023-01-28T23:08:03.550Z | General Question | v1 | What is the type for a pointer to a struct? | null | null | null |
63c648195f004bf4898cf969 | 2023-03-13T04:25:02.227Z | Help Write Code | v2 | null | null | null | I want to take a string like "main : dep1 dep2" and split it into the two strings "main" and "dep1 dep2" |
63c648195f004bf4898cf969 | 2023-03-13T04:26:37.376Z | General Question | v2 | How can you use strtok to handle multiple delimiter characters? | null | null | null |
63c648195f004bf4898cf969 | 2023-03-13T04:29:15.839Z | Explain Code | v2 | null | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char str_to_delim[] = "name : dep1 dep2";
strtok(str_to_delim, " :");
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-27T20:59:09.162Z | General Question | v1 | how do I get the size of an array that's passed into the main function | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-27T21:35:08.142Z | General Question | v1 | how do you get the size of **argv | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-27T21:36:38.574Z | General Question | v1 | How do you get the size of **argv that's passed into main | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-27T22:22:56.851Z | 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 **two_array = malloc(sizeof(int*) * 2);
if(length % 2 == 1){
two_array[0] = malloc(sizeof(int) * ((length / 2) + 1));
}
else{
two_array[0] = malloc(sizeof(int) * (length / 2));
}
two_array[1] = malloc(sizeof(int) * (length / 2));
int odd = 0;
int even = 0;
for(int i = 0; i < length; i++){
if(i % 2 == 0){
two_array[0][odd] = s[i];
odd++;
}
else{
two_array[0][even] = s[i];
even++;
}
}
return two_array;
}
/* 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 *full_array = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++){
full_array[i] = strtol(strs[i+ 1], NULL, 10);
printf("%d", full_array[i]);
}
return full_array;
}
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, argc - 1);
int **result = split_array(full_array, argc - 1);
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;
}
| Main is supposed to take a list of strings that are numbers. Then *build_array is supposed to convert the strings into numbers and return the array of numbers. Then **split_array is supposed to take the array made in *build_array, then create a 2d array where the first index is the odd indices of the int array, and the second index is the even indices of the int array. | null |
63c6481a5f004bf4898cf973 | 2023-01-27T22:27:24.494Z | 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 **two_array = malloc(sizeof(int*) * 2);
if(length % 2 == 1){
two_array[0] = malloc(sizeof(int) * ((length / 2) + 1));
}
else{
two_array[1] = malloc(sizeof(int) * (length / 2));
}
two_array[1] = malloc(sizeof(int) * (length / 2));
int odd = 0;
int even = 0;
for(int i = 0; i < length; i++){
if(i % 2 == 0){
two_array[0][odd] = s[i];
odd++;
}
else{
two_array[1][even] = s[i];
even++;
}
}
return two_array;
}
/* 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 *full_array = malloc(sizeof(int) * size);
for (int i = 0; i < size; i++){
full_array[i] = strtol(strs[i+ 1], NULL, 10);
printf("%d", full_array[i]);
}
return full_array;
}
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, argc - 1);
int **result = split_array(full_array, argc - 1);
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;
}
| Main is supposed to take a list of strings that are numbers. Then *build_array is supposed to convert the strings into numbers and return the array of numbers. Then **split_array is supposed to take the array made in *build_array, then create a 2d array where the first index is the odd indices of the int array, and the second index is the even indices of the int array. | null |
63c6481a5f004bf4898cf973 | 2023-01-29T22:22:47.106Z | General Question | v1 | How do I use command line from within a program | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-29T22:25:46.391Z | General Question | v1 | What is the variable type of system("ls -l") | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-29T22:32:25.202Z | General Question | v1 | Do I use char** to hold the information of system("ls -l") | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-29T23:43:11.233Z | General Question | v1 | Do I call scanf for each line that directed to it from the shell | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T00:56:45.998Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(){
char s[10];
char idk[31];
char username[31];
char groupname[31];
int size;
char month[3];
char date[3];
char time[6];
char filename[31];
scanf("%10s %31s %31s %31s %d %3s %3s %6s %31s", s, idk, username, groupname, &size, month, date, time, filename);
printf("%d\n", size);
return 0;
} | Supposed to take in a single line of input with 9 different variables and print the 5th one | null |
63c6481a5f004bf4898cf973 | 2023-01-30T00:59:38.249Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(){
char s[10];
char idk[31];
char username[31];
char groupname[31];
int size;
char month[3];
char date[3];
char time[6];
char filename[31];
scanf("%9s %30s %30s %30s %d %2s %2s %5s %30s", s, idk, username, groupname, &size, month, date, time, filename);
printf("%d\n", size);
return 0;
} | Supposed to take in a single line of input with 9 different variables and print the 5th one
| null |
63c6481a5f004bf4898cf973 | 2023-01-30T01:02:29.248Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(){
char s[10];
char idk[31];
char username[31];
char groupname[31];
int size;
char month[3];
char date[3];
char time[6];
char filename[31];
scanf("%9s %30s %30s %30s %d %2s %2s %5s %30s", s, idk, username, groupname, &size, month, date, time, filename);
printf("%d\n", size);
return 0;
} | Supposed to take in a single line of input with 9 different variables and print the 5th one (which is an integer) | null |
63c6481a5f004bf4898cf973 | 2023-01-30T01:05:46.429Z | Question from Code | v1 | Why is it printing a random number instead of the number I inputted | #include <stdio.h>
#include <stdlib.h>
int main(){
char s[10];
char idk[31];
char username[31];
char groupname[31];
int size;
char month[3];
char date[3];
char time[6];
char filename[31];
scanf("%9s %30s %30s %30s %d %2s %2s %5s %30s", s, idk, username, groupname, &size, month, date, time, filename);
printf("%d\n", size);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T01:10:01.612Z | Question from Code | v1 | Why is printf printing a random number when scanf sets the number before the printf function | #include <stdio.h>
#include <stdlib.h>
int main(){
char s[10];
char idk[31];
char username[31];
char groupname[31];
int size;
char month[3];
char date[3];
char time[6];
char filename[31];
scanf("%9s %30s %30s %30s %d %2s %2s %5s %30s", s, idk, username, groupname, &size, month, date, time, filename);
printf("%d\n", size);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T01:15:23.674Z | Question from Code | v1 | Why is printf printing a 0 when scanf should change size before the printf function
| #include <stdio.h>
#include <stdlib.h>
int main(){
char s[10];
char idk[31];
char username[31];
char groupname[31];
int size;
char month[3];
char date[3];
char time[6];
char filename[31];
size = 0;
scanf("%9s %30s %30s %30s %d %2s %2s %5s %30s", s, idk, username, groupname, &size, month, date, time, filename);
printf("%d\n", size);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T01:47:10.802Z | General Question | v1 | If we are inputting a file into a program from shell, can we tell how many lines are in the file | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T18:22:48.660Z | General Question | v1 | How do I take a subsection of a string | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T18:30:55.907Z | General Question | v1 | Can I split an input into two variables if there is no space between them | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T18:47:33.989Z | General Question | v1 | Can I split the input of a string into two by using %c first and then %8s | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T18:50:11.329Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char groupname[31];
int size;
size = 0;
scanf("%c %8s %30s %30s %30s %d", directory, permissions, idk, username, groupname, &size);
printf("%c %8s %d \n", directory, permissions, size);
return 0;
} | Code is supposed to take 4 strings and an int. The first string will be split into two with directory taking the first character of the string and then permissions taking the other 9 characters. The printf will print directory, permissions and size to make sure the first string was split properly and the integer was also taken correctly. | null |
63c6481a5f004bf4898cf973 | 2023-01-30T18:53:38.209Z | General Question | v1 | Does char name[10] specify a string that's 10 characters long or 9 characters long | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T18:56:56.397Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char groupname[31];
int size;
size = 0;
scanf("%c %9s %31s %31s %31s %d", &directory, permissions, idk, username, groupname, &size);
printf("%c %9s %d \n", directory, permissions, size);
return 0;
} | Code is supposed to take 4 strings and an int. The first string will be split into two with directory taking the first character of the string and then permissions taking the other 9 characters. The printf will print directory, permissions and size to make sure the first string was split properly and the integer was also taken correctly. | null |
63c6481a5f004bf4898cf973 | 2023-01-30T18:59:32.086Z | Question from Code | v1 | Why do I get the message "zsh: abort ./testing" after the proper output when the input is "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog" | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char groupname[31];
int size;
size = 0;
scanf("%c %9s %31s %31s %31s %d", &directory, permissions, idk, username, groupname, &size);
printf("%c %9s %d \n", directory, permissions, size);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:02:26.637Z | Question from Code | v1 | Why do I get the message:
"- rwx------ 1734
zsh: abort ./testing"
When the input is "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog" | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char groupname[31];
int size;
size = 0;
scanf("%c %9s %31s %31s %31s %d", &directory, permissions, idk, username, groupname, &size);
printf("%c %9s %d \n", directory, permissions, size);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:11:44.091Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char groupname[31];
int size;
char month[3];
int date;
char time[5];
char filename[31];
size = 0;
scanf(" %c %9s %31s %31s %31s %d %3s %d %5s %31s", &directory, permissions, idk, username, groupname, &size, month, &date, time, filename);
printf("%c %9s %31s %31s %d %3s %d %5s %31s \n", directory, permissions, idk, username, groupname, size, month, date, time, filename);
return 0;
} | Code is supposed to take 7 strings and 2 ints. The first string will be split into two with directory taking the first character of the string and then permissions taking the other 9 characters. The printf will print the variables. | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:17:17.587Z | Question from Code | v1 | Why does this input "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog", give this output "- rwx------ 1 reid staff 1536 Jun 0 14:52 prog
zsh: abort ./testing" | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
int size;
char month[3];
int date;
char time[5];
char filename[31];
size = 0;
scanf(" %c %9s %31s %31s %31s %d %3s %d %5s %31s", &directory, permissions, idk, username, group_name, &size, month, &date, time, filename);
printf("%c %9s %31s %31s %31s %d %3s %d %5s %31s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:23:34.436Z | Question from Code | v1 | Why does the input of "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog" give the correct characters and strings in the printf but wrong ints | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
int size;
char month[3];
int date;
char time[5];
char filename[31];
size = 0;
scanf("%c %s %s %s %s %d %s %d %s %s", &directory, permissions, idk, username, group_name, &size, month, &date, time, filename);
printf("%c %s %s %s %s %d %s %d %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:25:35.123Z | Question from Code | v1 | Why does the input of "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog" give the correct characters and strings in the printf but size = 1536 and date = 0 | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
int size;
char month[3];
int date;
char time[5];
char filename[31];
size = 0;
scanf("%c %s %s %s %s %d %s %d %s %s", &directory, permissions, idk, username, group_name, &size, month, &date, time, filename);
printf("%c %s %s %s %s %d %s %d %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:34:57.835Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[3];
char date[2];
char time[5];
char filename[31];
scanf("%c %s %s %s %s %s %s %s %s %s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
int size = strtol(s_size, NULL, 10);
printf("%c %s %s %s %s %d %s %s %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | Code is supposed to take 9 strings. The first string will be split into two with directory taking the first character of the string and then permissions taking the other 9 characters. Then s_size will be converted into an integer. Then all the variables except s_size are printed | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:36:46.024Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[3];
char date[2];
char time[5];
char filename[31];
scanf("%c %s %s %s %s %s %s %s %s %s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
int size = strtol(s_size, NULL, 10);
printf("%c %s %s %s %s %d %s %s %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | Code is supposed to take 9 strings. The first string is 10 characters long and will be split into two with directory taking the first character of the string and then permissions taking the other 9 characters. Then s_size will be converted into an integer. Then all the variables except s_size are printed | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:41:10.183Z | Question from Code | v1 | Why does the input of "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog" give the error of "zsh: abort" | -rwx------ 1 reid staff 1734 Jun 22 14:52 prog | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:42:44.676Z | Question from Code | v1 | Why does the input of "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog" give the error of "zsh: abort" | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[31];
char date[31];
char time[31];
char filename[31];
scanf(" %c %s %s %s %s %s %s %s %s %s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
int size = strtol(s_size, NULL, 10);
printf(" %c %s %s %s %s %d %s %s %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:44:23.110Z | Question from Code | v1 | Why does the input of "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog" give the error of "zsh: abort"
| #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[31];
char date[31];
char time[31];
char filename[31];
scanf("%c%s %s %s %s %s %s %s %s %s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
int size = strtol(s_size, NULL, 10);
printf("%c %s %s %s %s %d %s %s %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:45:44.235Z | Question from Code | v1 | How do I get the input of "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog" to not give the error of "zsh: abort" | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[31];
char date[31];
char time[31];
char filename[31];
scanf("%c%s %s %s %s %s %s %s %s %s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
int size = strtol(s_size, NULL, 10);
printf("%c %s %s %s %s %d %s %s %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:46:56.539Z | Question from Code | v1 | How do I get the input of "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog" to not give the error of "zsh: abort" | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[31];
char date[31];
char time[31];
char filename[31];
scanf("%c %s %s %s %s %s %s %s %s %s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
int size = strtol(s_size, NULL, 10);
printf("%c %s %s %s %s %d %s %s %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:53:43.186Z | Question from Code | v1 | Why does the input of "-rwx------ 1 reid staff 1734 Jun 22 14:52 prog", give correct print statement, but still give an error after | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[31];
char date[31];
char time[31];
char filename[31];
scanf("%c %s %s %s %s %s %s %s %s %s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
int size = strtol(s_size, NULL, 10);
printf("%c %s %s %s %s %d %s %s %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T19:58:56.093Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(){
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[31];
char date[31];
char time[31];
char filename[31];
scanf("%c %s %s %s %s %s %s %s %s %s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
int size = strtol(s_size, NULL, 10);
printf("%c %s %s %s %s %d %s %s %s %s \n", directory, permissions, idk, username, group_name, size, month, date, time, filename);
return 0;
} | Code is supposed to take 9 strings. The first string is 10 characters long and will be split into two with directory taking the first character of the string and then permissions taking the other 9 characters. Then s_size will be converted into an integer. Then all the variables except s_size are printed | null |
63c6481a5f004bf4898cf973 | 2023-01-30T21:56:34.360Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
int min_size = strtol(argv[1], NULL, 10);
int num_filtered_files = 0;
int eof = 1;
int first = 0;
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[31];
char date[31];
char time[31];
char filename[31];
int size = 1;
while(0 < eof){
if(first == 0){
eof = scanf("%c%s%s%s%s%s%s%s%s%s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
first = 1;
}
else{
eof = scanf("%c%s%s%s%s%s%s%s%s%s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
}
if(eof == 0){
break;
}
if (directory == '-'){
if(min_size < size){
num_filtered_files = num_filtered_files + 1;
}
}
}
printf("%d \n", num_filtered_files);
return 0;
}
| The main takes in a number and potentially a string in argv.
min_size is supposed to be the number given in argv.
Then, a "ls -l" of the current directory is given as the input.
The first line is supposed to be skipped as it does not match the form of the listed files.
The size of the file is first taken as a string, and then converted to an int.
If the size of the file is greater than min_size, the num_filtered_files increases by 1.
Finally num_filtered_files is printed. | null |
63c6481a5f004bf4898cf973 | 2023-01-30T22:01:09.214Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
int min_size = strtol(argv[1], NULL, 10);
int num_filtered_files = 0;
int eof = 1;
int first = 0;
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[31];
char date[31];
char time[31];
char filename[31];
int size;
while(0 < eof){
if(first == 0){
eof = scanf("%c%s%s%s%s%s%s%s%s%s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
first = 1;
}
else{
eof = scanf("%c%s%s%s%s%s%s%s%s%s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
}
if(eof == 0){
break;
}
size = strtol(s_size, NULL, 10);
if (directory == '-'){
if(min_size < size){
num_filtered_files = num_filtered_files + 1;
}
}
}
printf("%d \n", num_filtered_files);
return 0;
}
| The main takes in a number and potentially a string in argv. min_size is supposed to be the number given in argv. Then, a "ls -l" of the current directory is given as the input. The first line is supposed to be skipped as it does not match the form of the listed files. The size of the file is first taken as a string, and then converted to an int. If the size of the file is greater than min_size, the num_filtered_files increases by 1. Finally num_filtered_files is printed. | null |
63c6481a5f004bf4898cf973 | 2023-01-30T22:05:20.548Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int check_permissions(char *given, char *needed){
int same = 0;
for(int i = 0; i < 9; i++){
if(needed[i] != '-'){
if(needed[i] != given[i]){
same = 1;
break;
}
}
}
return same;
}
int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
int min_size = strtol(argv[1], NULL, 10);
int num_filtered_files = 0;
int eof = 1;
int first = 0;
char directory;
char permissions[9];
char idk[31];
char username[31];
char group_name[31];
char s_size[31];
char month[31];
char date[31];
char time[31];
char filename[31];
int size;
while(0 < eof){
if(first == 0){
char s1[10];
char s2[10];
eof = scanf("%s %s", s1, s2);
first = 1;
}
else{
eof = scanf("%c%s%s%s%s%s%s%s%s%s", &directory, permissions, idk, username, group_name, s_size, month, date, time, filename);
}
if(eof == 0){
break;
}
size = strtol(s_size, NULL, 10);
if (directory == '-'){
if(argc == 3 && min_size < size && check_permissions(permissions, argv[2]) == 0){
num_filtered_files ++;
}
else if(min_size < size){
num_filtered_files = num_filtered_files + 1;
}
}
}
printf("%d \n", num_filtered_files);
return 0;
}
| The main takes in a number and potentially a string in argv. min_size is supposed to be the number given in argv. Then, a "ls -l" of the current directory is given as the input. The first line is supposed to be skipped as it does not match the form of the listed files. The size of the file is first taken as a string, and then converted to an int. If the size of the file is greater than min_size, the num_filtered_files increases by 1. Finally num_filtered_files is printed. | null |
63c6481a5f004bf4898cf973 | 2023-01-30T23:26:23.905Z | Help Write Code | v1 | null | null | null | given an int, and an empty int array, convert each digit into a single place in the int array |
63c6481a5f004bf4898cf973 | 2023-01-30T23:28:26.708Z | General Question | v1 | How do I use modulo to get the individual digits of an int | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T23:36:44.843Z | General Question | v1 | If I give a helper function an empty array, how do I keep the changes to the array in main without returning the array | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-30T23:38:52.673Z | General Question | v1 | If I give the address of an int array to helper function, what should the argument for the helper function be. | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-31T00:35:03.710Z | General Question | v1 | Is it possible to keep the value of an int array that is edited in a helper function if the helper function's argument is also int array, and it doesn't return the array? | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-31T00:49:01.841Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int t_populate_array(int sin, int *sin_array) {
for (int i = 8; -1 < i; i--){
sin_array[i] = sin % 10;
if(sin == 0){
return 1;
}
sin = sin / 10;
}
return 0;
}
int main() {
int sin_arrayy[9];
int sin = 999999999;
int valid = t_populate_array(sin, &sin_arrayy);
for (int i = 0; i < 9; i++){
printf("%d \n", sin_arrayy[i]);
}
printf("Valid: %d \n", valid);
return 0;
} | Populate the empty integer array in a helper function, and return whether the given int was 9 digits long.
In the main function print the digits in the now populated array and whether the given number was 9 digits long | null |
63c6481a5f004bf4898cf973 | 2023-01-31T00:50:16.246Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <stdlib.h>
int t_populate_array(int sin, int *sin_array) {
for (int i = 8; -1 < i; i--){
sin_array[i] = sin % 10;
if(sin == 0){
return 1;
}
sin = sin / 10;
}
return 0;
}
int main() {
int sin_arrayy[9];
int sin = 999999999;
int valid = t_populate_array(sin, sin_arrayy);
for (int i = 0; i < 9; i++){
printf("%d \n", sin_arrayy[i]);
}
printf("Valid: %d \n", valid);
return 0;
} | Populate the empty integer array in a helper function, and return whether the given int was 9 digits long. In the main function print the digits in the now populated array and whether the given number was 9 digits long by either printing 0 or 1 | null |
63c6481a5f004bf4898cf973 | 2023-01-31T01:06:56.793Z | General Question | v1 | Can you keep the value of a variable in a helper function without malloc or returning the variable | null | null | null |
63c6481a5f004bf4898cf973 | 2023-01-31T01:14:49.100Z | General Question | v1 | How do I set the address of an int array to be an already declared integer | null | null | null |
63c6481a5f004bf4898cf973 | 2023-02-03T18:50:15.337Z | Help Fix Code | v1 | null | struct node{
int value;
struct node *next;
}; | Create a basic linked list class. | null |
63c6481a5f004bf4898cf973 | 2023-02-03T18:51:25.257Z | Help Fix Code | v1 | null | struct node{
int value;
struct node *next;
}; | Create a basic class. This class is supposed to act like a linked list. | null |
63c6481a5f004bf4898cf973 | 2023-02-03T19:01:33.451Z | Help Fix Code | v1 | null | typedef struct node{
int value;
Node *next;
}; | Create a basic class. This class is supposed to act like a linked list.
| null |
63c6481a5f004bf4898cf973 | 2023-02-03T19:49:56.065Z | General Question | v1 | In a linked list, why is the value of the next node, a pointer instead of the actual value of the node | null | null | null |
63c6481a5f004bf4898cf973 | 2023-02-03T19:58:19.277Z | General Question | v1 | If node *next is a pointer to a node, what is the value of next. | null | null | null |
63c6481a5f004bf4898cf973 | 2023-02-03T19:58:54.367Z | General Question | v1 | If node *two is a pointer to a node, what is the value of two | null | null | null |
63c6481a5f004bf4898cf973 | 2023-02-03T21:19:07.615Z | General Question | v1 | Are structs classes? | null | null | null |
63c6481a5f004bf4898cf973 | 2023-02-03T21:28:45.106Z | General Question | v1 | If you pass an array to a function, do you need to use malloc to keep the changes to the array | null | null | null |
63c6481a5f004bf4898cf973 | 2023-02-03T21:31:52.062Z | General Question | v1 | To keep changes to variables made in a function, do you pass a pointer to the variable | null | null | null |
63c6481a5f004bf4898cf973 | 2023-02-03T23:00:22.050Z | General Question | v1 | How do I compare strings in | null | null | null |
63c6481a5f004bf4898cf973 | 2023-02-03T23:05:26.787Z | General Question | v1 | If I take a string as an argument in the function, can I use strlen on it | null | null | null |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.