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
63c648c85f004bf4898cffae
2023-03-14T04:50:44.412Z
Help Write Code
v2
null
null
null
You will see that the actions are stored in a struct action_node that has a member args. This array has the format required by the second parameter to execvp. Use the man page for execvp to understand this format. In particular, notice that the first element is the executable name, subsequent elements are the arguments for that executable, and these are followed by an extra NULL pointer element
63c648c85f004bf4898cffae
2023-03-14T23:19:34.517Z
Explain Code
v2
null
char *arr[] = {};
null
null
63c648c85f004bf4898cffae
2023-03-15T23:23:26.435Z
Help Fix Code
v2
checks if the target exists. if not, then create a Rule and add it to the last node
Rule *create_target(Rule *rule, char *target_name) { Rule *curr = rule; // iterate over the rule node to check if the target already exists while (curr != NULL) { if (curr->target == target_name) { return curr; // if target does not exist, then create a new rule with the target // and add it to next to the last rule } else if (curr->next_rule == NULL) { Rule *new_rule; new_rule = malloc(sizeof(Rule)); if (new_rule == NULL) { perror("malloc"); exit(1); } int target_size = strlen(target_name) + 1; new_rule->target = malloc(target_size * sizeof(char *)); if (new_rule->target == NULL) { perror("malloc new target"); exit(1); } strcpy(new_rule->target, target_name); // new_rule->target[-1] = '\0'; new_rule->next_rule = NULL; curr->next_rule = new_rule; curr = curr->next_rule; return new_rule; } curr = curr->next_rule; } return curr; }
null
null
63c648c85f004bf4898cffae
2023-03-16T19:51:02.159Z
General Question
v2
One more experiment: Run your final greeting program in the foreground and kill it with Ctrl-c from the same window. Run it again and from another window, send it the USR1 signal to start the singing. While it is still singing, try to kill your greeting program using Ctrl-c from its own window (like you just did already.) What happens? Why?
null
null
null
63c648c85f004bf4898cffae
2023-03-17T05:50:34.759Z
Help Write Code
v2
null
null
null
You will write a C program that takes an integer argument s representing a number of seconds and a string representing the name of an existing binary file f, which contains 100 integers. The program will repeatedly generate a random integer from 0 to 99 and use that number as an index to read the corresponding integer from f. The program runs for s seconds and then reports how many reads were completed.
63c648c85f004bf4898cffae
2023-03-17T06:26:48.228Z
Help Write Code
v2
null
null
null
Since your program has to read integers from a binary file, you need to create a test file containing 100 integers. Write a small program, write_test_file.c, to do this task. It should take a single command-line argument representing a filename and create a file with that name that contains 100 integers. The values of the integers themselves don't matter, so start off by writing the integers 0 through 99 in order.
63c648c85f004bf4898cffae
2023-03-17T06:39:39.968Z
Help Write Code
v2
null
null
null
how to write numbers from 0 to 99 to a new biary file
63c648c85f004bf4898cffae
2023-03-17T17:35:17.724Z
Help Write Code
v2
null
null
null
write random integers between 0 and 99 to a file using random()
63c648c85f004bf4898cffae
2023-03-17T17:44:33.368Z
Help Write Code
v2
null
null
null
write code that goes into the loop body. Your program should seek to a random location in the file, read the integer at that location, and print it
63c648c85f004bf4898cffae
2023-03-17T18:35:30.258Z
Help Write Code
v2
null
null
null
Add code to set up a timer (using setitimerLinks to an external site.) for s seconds (where s is obtained from the command line). You shouldn't use real time, since your results will be affected if your system is busy. Instead, use ITIMER_PROF to make the itimer send a SIGPROF
63c648c85f004bf4898cffae
2023-03-17T19:44:17.885Z
Help Write Code
v2
null
null
null
Add code to set up a timer (using setitimerLinks to an external site.) for s seconds (where s is obtained from the command line). You shouldn't use real time, since your results will be affected if your system is busy. Instead, use ITIMER_PROF to make the itimer send a SIGPROF. Then change your signal handler to print a message to standard out (use the MESSAGE format in the starter code) that provides both the total number of reads completed and the time elapsed (s seconds).
63c648c85f004bf4898cffae
2023-03-17T20:49:38.252Z
Help Write Code
v2
null
null
null
In an infinite loop, read an int from a random location in the file, and print it to stderr.
63c648c85f004bf4898cffae
2023-03-17T20:59:51.422Z
Help Write Code
v2
null
null
null
write code that goes into the loop body. Your program should seek to a random location in the binary file, read the integer at that location, and print it to stderr
63c648c85f004bf4898cffae
2023-03-20T17:50:12.275Z
General Question
v2
What would we pass in as the type argument for socket() if we wanted to support datagrams?
null
null
null
63c648c85f004bf4898cffae
2023-03-20T18:00:50.990Z
General Question
v2
Which function do we call in order to convert an integer from the byte order of the host machine to network order?
null
null
null
63c648c85f004bf4898cffae
2023-03-20T18:11:35.315Z
General Question
v2
Which function would you use to find the IP address of a machine, given its name?
null
null
null
63c648c85f004bf4898cffae
2023-03-21T19:36:23.619Z
Help Write Code
v2
null
null
null
hange the code so that when the first client connects, they are told that they are player 1 and that we are waiting for player 2
63c648c85f004bf4898cffae
2023-03-24T19:07:36.043Z
Help Fix Code
v2
The main idea is that you have a buffer (a character array) where you store pieces of a message until you have a network newline ("\r\n"). Each message piece goes after the data that you've already placed in the buffer. When you find a network newline, you know that you have a complete message, so you can print that message and then shift any remaining bytes to the front of the buffer as the start of the next copy of the message.
while ((nbytes = read(fd, after, room)) > 0) { // Step 1: update inbuf (how many bytes were just added?) inbuf += nbytes; int where; // Step 2: the loop condition below calls find_network_newline // to determine if a full line has been read from the client. // Your next task should be to implement find_network_newline // (found at the bottom of this file). // // Note: we use a loop here because a single read might result in // more than one full line. while ((where = find_network_newline(buf, inbuf)) > 0) { // where is now the index into buf immediately after // the first network newline // Step 3: Okay, we have a full line. // Output the full line, not including the "\r\n", // using print statement below. // Be sure to put a '\0' in the correct place first; // otherwise you'll get junk in the output. buf[where - 2] = '\0'; printf("Next message: %s\n", buf); // Note that we could have also used write to avoid having to // put the '\0' in the buffer. Try using write later! // Step 4: update inbuf and remove the full line from the buffer // There might be stuff after the line, so don't just do inbuf = 0. // You want to move the stuff after the full line to the beginning // of the buffer. A loop can do it, or you can use memmove. // memmove(destination, source, number_of_bytes) int rem = inbuf - where; memmove(buf, buf + where, rem); inbuf = rem; } // Step 5: update after and room, in preparation for the next read. after = inbuf + buf; room = sizeof(buf) - inbuf; }
null
null
63c648ca5f004bf4898cffc2
2023-01-24T22:27:35.876Z
Help Fix Code
v1
null
int check_permissions(char * file, char * req){ for (int i = 0; i < 9 ; i++){ if (req[i] != '-'){ if (file[i] != req[i]){ return 1; } } } return 0; } int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } char *after; char *before; int size; int count; // TODO: Process command line arguments. scanf("Total %*d\n"); while(scanf("%s %d %s\n", before, &size, after) != EOF){ if (size > strtol(argv[1], NULL, 10) && before[0] != 'd'){ if (argc == 3){ if (!check_permissions(before, argv[2])){ count ++; } } else{ count ++; } } } printf("%d", count); // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. return 0; }
null
null
63c648cc5f004bf4898cffd1
2023-01-17T20:37:38.694Z
General Question
v1
how to declare a string
null
null
null
63c648cc5f004bf4898cffd1
2023-01-20T03:31:56.456Z
General Question
v1
how to use scanf
null
null
null
63c648cc5f004bf4898cffd1
2023-01-20T03:47:26.938Z
General Question
v1
how to print variables
null
null
null
63c648cc5f004bf4898cffd1
2023-01-20T04:02:57.186Z
General Question
v1
how to scan a string using scanf
null
null
null
63c648cc5f004bf4898cffd1
2023-01-20T04:04:38.791Z
Help Fix Code
v1
null
char phone[11]; scanf("%s", &phone);
null
null
63c648cc5f004bf4898cffd1
2023-01-20T04:54:52.475Z
General Question
v1
what is the value of EOF
null
null
null
63c648cc5f004bf4898cffd1
2023-01-24T02:10:06.841Z
General Question
v1
how to ignore standard input from scanf?
null
null
null
63c648cc5f004bf4898cffd1
2023-01-24T02:38:13.185Z
General Question
v1
how to convert a string to an integer
null
null
null
63c648cc5f004bf4898cffd1
2023-01-24T02:54:31.326Z
Question from Code
v1
How do I fix the warnings?
int check_permissions(char *file, char *required){ for (int i = 0; i < 9; i++){ if (file[i] != "-" && file[i] != required[i]){ return 1; } } return 0; }
null
null
63c648cc5f004bf4898cffd1
2023-01-24T02:56:53.186Z
General Question
v1
what type is "-"
null
null
null
63c648cc5f004bf4898cffd1
2023-01-24T02:58:53.885Z
Help Fix Code
v1
null
int check_permissions(char *file, char *required){ for (int i = 0; i < 9; i++){ if (file[i] != "-" && file[i] != required[i]){ return 1; } } return 0; }
Return 1 if file[i] != "-" and file[i] != required[i] for any i between 0 and 8.
null
63c648cc5f004bf4898cffd1
2023-01-24T03:21:49.518Z
General Question
v1
how does scanf work when its standard input takes multiple lines?
null
null
null
63c648cc5f004bf4898cffd1
2023-01-25T03:48:47.643Z
Help Fix Code
v1
null
int main(int argc, char** argv) { char requirements[10]; requirements = argv[1]; }
Accept a string as an input to store in memory.
null
63c648cc5f004bf4898cffd1
2023-01-25T03:52:48.875Z
General Question
v1
how to store a string in a variable
null
null
null
63c648cc5f004bf4898cffd1
2023-01-25T03:55:12.397Z
General Question
v1
how to accept a string as an argument in main
null
null
null
63c648cc5f004bf4898cffd1
2023-01-25T15:53:20.604Z
General Question
v1
how to use pow function
null
null
null
63c648cc5f004bf4898cffd1
2023-01-25T19:53:05.267Z
General Question
v1
how to ignore a character when using scanf
null
null
null
63c648cc5f004bf4898cffd1
2023-01-25T19:53:36.645Z
General Question
v1
how to scan a character using scanf
null
null
null
63c648cc5f004bf4898cffd1
2023-01-31T20:29:46.714Z
General Question
v1
how to declare an array
null
null
null
63c648cc5f004bf4898cffd1
2023-01-31T20:38:13.942Z
General Question
v1
how to declare an array of strings
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T16:51:21.266Z
General Question
v1
how to compare the values of two objects?
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T16:53:14.973Z
General Question
v1
how to compare two arguments from main
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T16:54:41.172Z
General Question
v1
can a string be converted into an int?
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T17:00:16.002Z
Help Fix Code
v1
null
int main(int argc, char **argv){ int x; int y; if (argc != 3){ printf("Invalid\n"); return 0; } else{ x = atoi(argv[1]); y = atoi(argv[2]); if (x == y) { printf("Same\n"); return 0; } else { printf("Different\n"); return 0; } } }
determine if argv[1] is equal to argv[2]
null
63c648cc5f004bf4898cffd1
2023-02-02T17:01:20.328Z
Question from Code
v1
How do I fix the warnings from my code?
int main(int argc, char **argv){ int x; int y; if (argc != 3){ printf("Invalid\n"); return 0; } else{ x = atoi(argv[1]); y = atoi(argv[2]); if (x == y) { printf("Same\n"); return 0; } else { printf("Different\n"); return 0; } } }
null
null
63c648cc5f004bf4898cffd1
2023-02-02T17:14:40.125Z
General Question
v1
how to compare strings
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T17:39:52.354Z
General Question
v1
how to truncate a string literal
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T17:40:32.678Z
General Question
v1
how to find the length of a string
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T17:56:39.942Z
General Question
v1
how to make a function that takes a string literal and truncates it
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T22:25:00.226Z
General Question
v1
Are you allowed to modify the arguments of main?
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T22:25:19.601Z
General Question
v1
Are you allowed to modify string literals?
null
null
null
63c648cc5f004bf4898cffd1
2023-02-02T22:26:11.792Z
Question from Code
v1
Can I modify target if it is a string literal?
int truncate(char *target, int amt){ int size = 0; for(int i = 0; target[i] != '\0'; i++){ size = size + 1; } target[amt] = '\0'; return (size - amt); }
null
null
63c648cc5f004bf4898cffd1
2023-02-02T22:27:08.857Z
Question from Code
v1
Why can I modify a string literal with this function?
int truncate(char *target, int amt){ int size = 0; for(int i = 0; target[i] != '\0'; i++){ size = size + 1; } target[amt] = '\0'; return (size - amt); }
null
null
63c648cc5f004bf4898cffd1
2023-02-10T04:34:39.033Z
General Question
v1
how to use fread to read a single integer
null
null
null
63c648cc5f004bf4898cffd1
2023-02-10T04:38:22.534Z
Help Fix Code
v1
null
void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { fseek(image, 10, SEEK_SET); fread(&pixel_array_offset, 4, 1, image); fseek(image, 21, SEEK_SET); fread(&width, 4, 1, image); fseek(image, 21, SEEK_SET); fread(&height, 4, 1, image); }
read the proper values from file and store the read values in width and height
null
63c648cc5f004bf4898cffd1
2023-02-10T06:03:42.935Z
General Question
v1
how to initialize a two dimensional array of integers
null
null
null
63c648cc5f004bf4898cffd1
2023-02-10T17:22:46.811Z
General Question
v1
how in initialize an unsigned char
null
null
null
63c648cc5f004bf4898cffd1
2023-02-12T21:23:59.699Z
General Question
v1
how to read an ascii file and print it to standard output
null
null
null
63c648cc5f004bf4898cffd1
2023-02-13T21:19:44.356Z
General Question
v1
How to print the current time and date?
null
null
null
63c648cc5f004bf4898cffd1
2023-03-06T20:14:30.635Z
General Question
v1
How to access the seconds and nanoseconds from a time_t object?
null
null
null
63c648cc5f004bf4898cffd1
2023-03-07T01:43:21.581Z
General Question
v1
how to use execvp?
null
null
null
63c648cc5f004bf4898cffd1
2023-03-15T16:17:34.747Z
General Question
v2
how to use setitimer?
null
null
null
63c648cc5f004bf4898cffd1
2023-03-23T00:37:44.213Z
General Question
v2
how to compare two characters?
null
null
null
63c648cc5f004bf4898cffd1
2023-04-01T23:49:45.331Z
General Question
v2
how to use the function snprintf
null
null
null
63c648cc5f004bf4898cffd1
2023-04-01T23:52:28.354Z
Help Write Code
v2
null
null
null
create a code example that uses the function snprintf
63c648cd5f004bf4898cffe0
2023-01-18T02:06:01.182Z
General Question
v1
What is wrong here
null
null
null
63c648cd5f004bf4898cffe0
2023-01-18T02:07:21.643Z
Help Fix Code
v1
null
#include <stdlib.h> #include <stdio.h> int main(){ float *rainfall = Null; *rainfall = malloc(sizeof(rainfall)); *rainfall = 42.6; return 0; }
null
null
63c648cd5f004bf4898cffe0
2023-01-18T02:42:08.577Z
General Question
v1
run the code
null
null
null
63c648cd5f004bf4898cffe0
2023-01-18T02:42:34.769Z
Question from Code
v1
run the code
#include <stdlib.h> #include <stdio.h> int main(){ int x = sizeof(float) * 42.6; printf("%d", x); }
null
null
63c648cd5f004bf4898cffe0
2023-01-18T02:46:18.152Z
Question from Code
v1
run the code
#include <stdlib.h> #include <stdio.h> int main(){ float *rainfall = NULL; rainfall = malloc(sizeof(float)); *rainfall = 42.6; int x = sizeof(rainfall); printf("%d", x); }
null
null
63c648cf5f004bf4898cffef
2023-01-25T03:31:19.485Z
Explain Code
v1
null
int *build_array(char **strs, int size) { int *result = malloc(size * sizeof(int)); for (int i = 1; i < size + 1; i++) { result[i - 1] = strtol(strs[i], NULL, 10); } return result; }
null
null
63c648cf5f004bf4898cffef
2023-01-25T03:32:42.526Z
Explain Code
v1
null
int **split_array(const int *s, int length) { int **result = malloc(2 * sizeof(int*)); int odd_len; int even_len = length / 2; if (length % 2 == 0) { odd_len = length / 2; } else { odd_len = (length / 2) + 1; } int *odd = malloc(odd_len * sizeof(int)); int *even = malloc(even_len * sizeof(int)); for (int i = 0; i < length; i++) { if (i % 2 == 0) { even[i / 2] = s[i]; } else { odd[i / 2] = s[i]; } } *result[0] = *odd; *result[1] = *even; return result; }
null
null
63c648cf5f004bf4898cffef
2023-01-25T04:02:48.275Z
Help Fix Code
v1
null
int **split_array(const int *s, int length) { int **result = malloc(2 * sizeof(int*)); int odd_len; int even_len = length / 2; if (length % 2 == 0) { odd_len = length / 2; } else { odd_len = (length / 2) + 1; } int *odd = malloc(odd_len * sizeof(int)); int *even = malloc(even_len * sizeof(int)); for (int i = 0; i < length; i++) { if (i % 2 == 0) { even[i / 2] = s[i]; } else { odd[i / 2] = s[i]; } } *result[0] = *odd; *result[1] = *even; return result; }
returning two arrays with one odd index and one even index
null
63c648cf5f004bf4898cffef
2023-02-15T03:42:28.868Z
Help Fix Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { int found_name1 = 0; int found_name2 = 0; while (head != NULL) { if (strcmp(head->name, name1) == 0) { found_name1 = 1; } else if (strcmp(head->name, name2) == 0) { found_name2 = 1; } head = head->next; } if (found_name1 == 0 || found_name2 == 0) { return 4; } if (strcmp(name1, name2) == 0) { return 3; } User *user1 = head; User *user2 = head; User *user1_friend_empty = head; User *user2_friend_empty = head; int are_friends1 = 0; int are_friends2 = 0; while (head->next != NULL) { if (strcmp(head->name, name1) == 0) { user1 = head; for (int i = 0; i < MAX_FRIENDS; i++) { if (i - 1 > MAX_FRIENDS) { return 2; } if (strcmp(((head->friends)[i])->name, name2) == 0) { return 1; } if (strcmp(((head->friends)[i])->name, name2)) { are_friends1 = 1; break; } if ((head->friends)[i] == NULL) { user1_friend_empty = (head->friends)[i]; break; } } } if (strcmp(head->name, name2) == 0) { user2 = head; for (int i = 0; i < MAX_FRIENDS; i++) { if (i - 1 > MAX_FRIENDS) { return 2; } if (strcmp(((head->friends)[i])->name, name1) == 0) { return 1; } if (strcmp(((head->friends)[i])->name, name1)) { are_friends2 = 1; break; } if ((head->friends)[i] == NULL) { user2_friend_empty = (head->friends)[i]; break; } } } head = head->next; } if (are_friends1 == 1 && are_friends2 == 1) { return 1; } else { user1_friend_empty = user2; user2_friend_empty = user1; return 0; } }
make the unused variable use
null
63c648cf5f004bf4898cffef
2023-02-15T03:44:06.612Z
Question from Code
v1
why are the variable unused
int make_friends(const char *name1, const char *name2, User *head) { int found_name1 = 0; int found_name2 = 0; while (head != NULL) { if (strcmp(head->name, name1) == 0) { found_name1 = 1; } else if (strcmp(head->name, name2) == 0) { found_name2 = 1; } head = head->next; } if (found_name1 == 0 || found_name2 == 0) { return 4; } if (strcmp(name1, name2) == 0) { return 3; } User *user1 = head; User *user2 = head; User *user1_friend_empty = head; User *user2_friend_empty = head; int are_friends1 = 0; int are_friends2 = 0; while (head->next != NULL) { if (strcmp(head->name, name1) == 0) { user1 = head; for (int i = 0; i < MAX_FRIENDS; i++) { if (i - 1 > MAX_FRIENDS) { return 2; } if (strcmp(((head->friends)[i])->name, name2) == 0) { return 1; } if (strcmp(((head->friends)[i])->name, name2)) { are_friends1 = 1; break; } if ((head->friends)[i] == NULL) { user1_friend_empty = (head->friends)[i]; break; } } } if (strcmp(head->name, name2) == 0) { user2 = head; for (int i = 0; i < MAX_FRIENDS; i++) { if (i - 1 > MAX_FRIENDS) { return 2; } if (strcmp(((head->friends)[i])->name, name1) == 0) { return 1; } if (strcmp(((head->friends)[i])->name, name1)) { are_friends2 = 1; break; } if ((head->friends)[i] == NULL) { user2_friend_empty = (head->friends)[i]; break; } } } head = head->next; } if (are_friends1 == 1 && are_friends2 == 1) { return 1; } else { user1_friend_empty = user2; user2_friend_empty = user1; return 0; } }
null
null
63c648cf5f004bf4898cffef
2023-02-15T04:27:06.130Z
Question from Code
v1
why is there segamentatuin fault
int create_user(const char *name, User **user_ptr_add) { if (strlen(name) >= MAX_NAME) { return 2; } User *curr = *user_ptr_add; User *new_user = malloc(sizeof(User)); while (curr != NULL) { if (strcmp(curr->name, name) == 0) { return 1; } curr = curr->next; } strcpy(new_user->name, name); new_user->next = NULL; if (user_ptr_add == NULL) { *user_ptr_add = new_user; } else { curr = *user_ptr_add; while (curr != NULL) { curr = curr->next; } curr->next = new_user; } return 0; }
null
null
63c648cf5f004bf4898cffef
2023-02-15T09:59:35.016Z
Question from Code
v1
which pointer isn't allocated
int delete_user(const char *name, User **user_ptr_del) { User *head = *user_ptr_del; User *target = find_user(name, head); if (target == NULL) { return 1; } // delete friends while (head != NULL) { for (int i = 0; i < MAX_FRIENDS; i++) { if (head->friends[i] == NULL) { break; } if (strcmp(head->friends[i]->name, name) == 0) { head->friends[i] = NULL; //shift other friends to avoid NULL in between friends for (int j = i - 1; j < MAX_FRIENDS - 1; j++) { head->friends[j] = head->friends[j + 1]; } } } head = head->next; } // delete posts Post *curr_post = target->first_post; while (curr_post != NULL) { Post *next_post = curr_post->next; free(curr_post->author); free(curr_post->date); free(curr_post->contents); free(curr_post); curr_post = next_post; } //delete user User *curr_user = *user_ptr_del; // when target is the first user if (strcmp(curr_user->name, name) == 0) { *user_ptr_del = curr_user->next; free(curr_user->name); free(curr_user->profile_pic); for (int i = 0; i < MAX_FRIENDS; i++) { free(curr_user->friends[i]); } free(curr_user->friends); free(curr_user); return 0; //when target is the last user } else if (curr_user->next == NULL) { free(curr_user->next->name); free(curr_user->next->profile_pic); for (int i = 0; i < MAX_FRIENDS; i++) { free(curr_user->next->friends[i]); } free(curr_user->friends); free(curr_user->next); curr_user->next = NULL; return 0; } else { while (curr_user->next != NULL) { if (strcmp(curr_user->next->name, name) == 0) { User *next_user = curr_user->next->next; free(curr_user->next->name); free(curr_user->next->profile_pic); for (int i = 0; i < MAX_FRIENDS; i++) { free(curr_user->next->friends[i]); } free(curr_user->next->friends); free(curr_user->next); curr_user->next = next_user; return 0; } curr_user = curr_user->next; } } return 1; }
null
null
63c648cf5f004bf4898cffef
2023-02-15T10:00:17.079Z
Question from Code
v1
which pointer at which line isn't allocated
int delete_user(const char *name, User **user_ptr_del) { User *head = *user_ptr_del; User *target = find_user(name, head); if (target == NULL) { return 1; } // delete friends while (head != NULL) { for (int i = 0; i < MAX_FRIENDS; i++) { if (head->friends[i] == NULL) { break; } if (strcmp(head->friends[i]->name, name) == 0) { head->friends[i] = NULL; //shift other friends to avoid NULL in between friends for (int j = i - 1; j < MAX_FRIENDS - 1; j++) { head->friends[j] = head->friends[j + 1]; } } } head = head->next; } // delete posts Post *curr_post = target->first_post; while (curr_post != NULL) { Post *next_post = curr_post->next; free(curr_post->author); free(curr_post->date); free(curr_post->contents); free(curr_post); curr_post = next_post; } //delete user User *curr_user = *user_ptr_del; // when target is the first user if (strcmp(curr_user->name, name) == 0) { *user_ptr_del = curr_user->next; free(curr_user->name); free(curr_user->profile_pic); for (int i = 0; i < MAX_FRIENDS; i++) { free(curr_user->friends[i]); } free(curr_user->friends); free(curr_user); return 0; //when target is the last user } else if (curr_user->next == NULL) { free(curr_user->next->name); free(curr_user->next->profile_pic); for (int i = 0; i < MAX_FRIENDS; i++) { free(curr_user->next->friends[i]); } free(curr_user->friends); free(curr_user->next); curr_user->next = NULL; return 0; } else { while (curr_user->next != NULL) { if (strcmp(curr_user->next->name, name) == 0) { User *next_user = curr_user->next->next; free(curr_user->next->name); free(curr_user->next->profile_pic); for (int i = 0; i < MAX_FRIENDS; i++) { free(curr_user->next->friends[i]); } free(curr_user->next->friends); free(curr_user->next); curr_user->next = next_user; return 0; } curr_user = curr_user->next; } } return 1; }
null
null
63c648cf5f004bf4898cffef
2023-02-15T10:04:09.137Z
Question from Code
v1
which pointer is invalid
int delete_user(const char *name, User **user_ptr_del) { User *head = *user_ptr_del; User *target = find_user(name, head); if (target == NULL) { return 1; } // delete friends while (head != NULL) { for (int i = 0; i < MAX_FRIENDS; i++) { if (head->friends[i] == NULL) { break; } if (strcmp(head->friends[i]->name, name) == 0) { head->friends[i] = NULL; //shift other friends to avoid NULL in between friends for (int j = i - 1; j < MAX_FRIENDS - 1; j++) { head->friends[j] = head->friends[j + 1]; } } } head = head->next; } // delete posts Post *curr_post = target->first_post; while (curr_post != NULL) { Post *next_post = curr_post->next; free(curr_post->author); free(curr_post->date); free(curr_post->contents); free(curr_post); curr_post = next_post; } //delete user User *curr_user = *user_ptr_del; // when target is the first user if (strcmp(curr_user->name, name) == 0) { *user_ptr_del = curr_user->next; free(curr_user->name); free(curr_user->profile_pic); for (int i = 0; i < MAX_FRIENDS; i++) { free(curr_user->friends[i]); } free(curr_user->friends); free(curr_user); return 0; //when target is the last user } else if (curr_user->next == NULL) { free(curr_user->next->name); free(curr_user->next->profile_pic); // for (int i = 0; i < MAX_FRIENDS; i++) { // free(curr_user->next->friends[i]); // } free(curr_user->friends); free(curr_user->next); curr_user->next = NULL; return 0; } else { while (curr_user->next != NULL) { if (strcmp(curr_user->next->name, name) == 0) { User *next_user = curr_user->next->next; free(curr_user->next->name); free(curr_user->next->profile_pic); // for (int i = 0; i < MAX_FRIENDS; i++) { // free(curr_user->next->friends[i]); // } // free(curr_user->next->friends); free(curr_user->next); curr_user->next = next_user; return 0; } curr_user = curr_user->next; } } return 1; }
null
null
63c648d05f004bf4898cfff9
2023-02-01T07:25:20.607Z
General Question
v1
Why is pointer a pointer
null
null
null
63c648d05f004bf4898cfff9
2023-02-03T03:34:17.853Z
Help Fix Code
v1
null
char string1; strcpy(string1, argv[1]);
want to store the strings from argv[1] to string 1
null
63c648d05f004bf4898cfff9
2023-02-03T03:47:42.785Z
General Question
v1
can I change an element in a string literal
null
null
null
63c648d05f004bf4898cfff9
2023-02-03T03:49:02.485Z
Question from Code
v1
what is the type of string a? is it string or string literal?
char *a = argv[2];
null
null
63c648d05f004bf4898cfff9
2023-02-03T04:07:18.706Z
General Question
v1
how to truncate a string literal
null
null
null
63c648d05f004bf4898cfff9
2023-02-03T04:24:08.707Z
General Question
v1
how to truncate a pointer to char with size n
null
null
null
63c648d05f004bf4898cfff9
2023-02-03T04:24:55.571Z
Question from Code
v1
can i change the element in string a?
char *a = argv[2];
null
null
63c648d05f004bf4898cfff9
2023-02-03T04:26:15.385Z
General Question
v1
what is a string literal?
null
null
null
63c648d05f004bf4898cfff9
2023-02-03T06:09:17.897Z
General Question
v1
how to change a element to a space character in a string
null
null
null
63c648d15f004bf4898d0003
2023-01-20T03:55:33.773Z
Explain Code
v1
null
int sum_card(int **score_card, int size) { // TODO: write the body of sum_card according to its description. int sum=0; for(int i=0; i < size; i++) { sum += score_card[i]; } return sum; }
null
null
63c648d15f004bf4898d0003
2023-01-20T03:57:03.178Z
Explain Code
v1
null
int sum_card(int **score_card, int size) { // TODO: write the body of sum_card according to its description. int sum=0; for(int i=0; i < size; i++) { sum += score_card[i]; } return sum; } 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
63c648d15f004bf4898d0003
2023-01-20T03:58:53.104Z
Explain Code
v1
null
#include <stdio.h> #include <stdlib.h> /* * Write a void function invest that takes your money and multiplies it by the given rate. */ void invest(double *principal_pt, double rate) { *principal_pt *= rate; } /* * NOTE: don't change the main function! * Sample usage: * $ gcc -Wall -std=gnu99 -g -o invest invest.c * $ ./invest 10000 1.05 * 10500.00 */ int main(int argc, char **argv) { // Read in the command-line arguments and convert the strings to doubles double principal = strtod(argv[1], NULL); double rate = strtod(argv[2], NULL); // Call invest to make you more money invest(&principal, rate); printf("%.2f\n", principal); return 0; }
null
null
63c648d15f004bf4898d0003
2023-01-20T04:00:07.936Z
Help Write Code
v1
null
null
null
Your task is to write a small C program called phone.c that uses scanf to read two values from standard input. The first is a 10 character string and the second is an integer. The program takes no command-line arguments. (You will write this program from scratch, so remember to add, commit, and push.) If the integer is -1, the program prints the full string to stdout. If the integer i is between 0 and 9, the program prints only the corresponding character (i.e., at index i) from the string to stdout. In both of these cases the program returns 0. If the integer is less than -1 or greater than 9, the program prints the message "ERROR" to stdout and returns 1.
63c648d15f004bf4898d0003
2023-01-27T04:52:04.683Z
Help Fix Code
v1
null
void fib(int **fib_sequence, int n) { *fib_sequence = malloc(sizeof(int) * n); int *arr = *fib_sequence; arr[0] = 0; if(n > 1) { arr[1] = 1; for(int i=2; i <= n; i++) { arr[i] = arr[i-2] + arr[i-1]; } } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
Define a function void fib(...) below. This function takes parameter n and generates the first n values in the Fibonacci sequence. The values should be stored in a dynamically-allocated array composed of exactly the correct number of integers. The values should be returned through a pointer parameter passed in as the first argument.
null
63c648d15f004bf4898d0003
2023-01-27T04:56:51.103Z
Help Fix Code
v1
null
void fib(int **fib_sequence, int n) { *fib_sequence = malloc(sizeof(int) * n); int *arr = *fib_sequence; arr[0] = 0; if(n > 1) { arr[1] = 1; for(int i=2; i < n; i++) { arr[i] = arr[i-2] + arr[i-1]; } } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
Define a function void fib(...) below. This function takes parameter n and generates the first n values in the Fibonacci sequence. The values should be stored in a dynamically-allocated array composed of exactly the correct number of integers. The values should be returned through a pointer parameter passed in as the first argument.
null
63c648d15f004bf4898d0003
2023-01-27T05:10:25.061Z
Help Fix Code
v1
null
void fib(int **fib_sequence, int n) { *fib_sequence = malloc(sizeof(int) * n); fib_sequence[0] = 0; if(n > 1) { fib_sequence[1] = 1; for(int i=2; i < n; i++) { fib_sequence[i] = fib_sequence[i-2] + fib_sequence[i-1]; } } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
Define a function void fib(...) below. This function takes parameter n and generates the first n values in the Fibonacci sequence. The values should be stored in a dynamically-allocated array composed of exactly the correct number of integers. The values should be returned through a pointer parameter passed in as the first argument.
null
63c648d15f004bf4898d0003
2023-01-27T05:12:00.285Z
Help Fix Code
v1
null
void fib(int **fib_sequence, int n) { **fib_sequence = malloc(sizeof(int) * n); *fib_sequence[0] = 0; if(n > 1) { *fib_sequence[1] = 1; for(int i=2; i < n; i++) { *fib_sequence[i] = *fib_sequence[i-2] + *fib_sequence[i-1]; } } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
Define a function void fib(...) below. This function takes parameter n and generates the first n values in the Fibonacci sequence. The values should be stored in a dynamically-allocated array composed of exactly the correct number of integers. The values should be returned through a pointer parameter passed in as the first argument.
null
63c648d15f004bf4898d0003
2023-01-27T05:13:15.665Z
Help Fix Code
v1
null
void fib(int **fib_sequence, int n) { **fib_sequence = malloc(sizeof(int) * n); (*fib_sequence)[0] = 0; if(n > 1) { (*fib_sequence)[1] = 1; for(int i=2; i < n; i++) { (*fib_sequence)[i] = (*fib_sequence)[i-2] + (*fib_sequence)[i-1]; } } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
Define a function void fib(...) below. This function takes parameter n and generates the first n values in the Fibonacci sequence. The values should be stored in a dynamically-allocated array composed of exactly the correct number of integers. The values should be returned through a pointer parameter passed in as the first argument.
null
63c648d15f004bf4898d0003
2023-01-27T05:14:07.346Z
Help Fix Code
v1
null
void fib(int **fib_sequence, int n) { *fib_sequence = malloc(sizeof(int) * n); (*fib_sequence)[0] = 0; if(n > 1) { (*fib_sequence)[1] = 1; for(int i=2; i < n; i++) { (*fib_sequence)[i] = (*fib_sequence)[i-2] + (*fib_sequence)[i-1]; } } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
Define a function void fib(...) below. This function takes parameter n and generates the first n values in the Fibonacci sequence. The values should be stored in a dynamically-allocated array composed of exactly the correct number of integers. The values should be returned through a pointer parameter passed in as the first argument.
null
63c648d15f004bf4898d0003
2023-01-27T05:22:24.562Z
General Question
v1
What does this error mean: malloc.c:2379: sysmalloc: Assertion
null
null
null
63c648d15f004bf4898d0003
2023-01-27T06:32:29.552Z
Help Fix Code
v1
null
int **split_array(const int *s, int length) { int **result = malloc(sizeof(int) * 2); result[0] = malloc(sizeof(int) * length + 1 / 2); result[1] = malloc(sizeof(int) * length + 1 / 2); int even = 0; int odd = 0; for(int i = 0; i < length; i ++){ if(s[i] % 2 == 0) { result[0][even] = s[i]; even++; } else { result[1][odd] = s[i]; odd++; } } return result; }
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.
null
63c648d15f004bf4898d0003
2023-01-27T06:34:15.101Z
Help Fix Code
v1
null
int **split_array(const int *s, int length) { int **result = malloc(sizeof(int*) * 2); result[0] = malloc(sizeof(int) * (length + 1) / 2); result[1] = malloc(sizeof(int) * (length + 1) / 2); int even = 0; int odd = 0; for(int i = 0; i < length; i ++){ if(s[i] % 2 == 0) { result[0][even] = s[i]; even++; } else { result[1][odd] = s[i]; odd++; } } return result; }
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.
null