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
⌀ |
---|---|---|---|---|---|---|---|
63c647e85f004bf4898cf7b1 | 2023-02-10T22:13:06.058Z | General Question | v1 | how to allocate space on the stack for a struct pointer? | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-02-10T22:26:52.408Z | Question from Code | v1 | what does this look like in memory? | struct pixel **st_pixels;
st_pixels = malloc(sizeof(struct pixel *) * height);
| null | null |
63c647e85f004bf4898cf7b1 | 2023-02-11T23:46:00.410Z | General Question | v1 | an array of pointers to structs | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-02-12T02:24:26.354Z | General Question | v1 | how to traverse a linked list to find a specific struct | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-03T00:01:19.043Z | General Question | v1 | explain fork() | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-10T19:25:23.883Z | Explain Code | v2 | null | int main(int argc, char **argv) {
// Declare any variables you need
int fd[argc][2];
int one_value;
// Write the code to loop over the command line arguments
for (int i = 1; i < argc; i++) {
// Call pipe before we fork
if (pipe(fd[i]) == -1) {
perror("pipe");
exit(1);
}
// Call fork
int result = fork();
if (result < 0) {
perror("fork");
exit(1);
} else if (result == 0) {
// Child only writes to the pipe, so close reading end
Close(fd[i][0]);
// Before we forked, parent had open the reading ends to
// all previously forked children; so close those.
for (int j = 1; j < i; j++) {
Close(fd[j][0]);
}
// Now do the work - write the value in binary to the pipe
int length = strlen(argv[i]);
write(fd[i][1], &length, sizeof(int));
// Close the pipe since we are done with it.
Close(fd[i][1]);
exit(0);
} else {
// In the parent, but before doing the next loop iteration,
// close the end of the pipe that we don't want open
Close(fd[i][1]);
}
}
// Only the parent gets here
int sum = 0;
for (int i = 1; i < argc; i++) {
// Read one integer from each child
read(fd[i][0], &one_value, sizeof(int));
printf("I just read %d from pipe %d\n", one_value, i);
sum += one_value;
}
printf("Sum is %d\n", sum);
return 0;
} | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-10T19:58:03.625Z | Question from Code | v2 | when would we ever get to the else branch | int main(int argc, char **argv) {
// Declare any variables you need
int fd[argc][2];
int one_value;
// Write the code to loop over the command line arguments
for (int i = 1; i < argc; i++) {
// Call pipe before we fork
if (pipe(fd[i]) == -1) {
perror("pipe");
exit(1);
}
// Call fork
int result = fork();
if (result < 0) {
perror("fork");
exit(1);
} else if (result == 0) {
// Child only writes to the pipe, so close reading end
Close(fd[i][0]);
// Before we forked, parent had open the reading ends to
// all previously forked children; so close those.
for (int j = 1; j < i; j++) {
Close(fd[j][0]);
}
// Now do the work - write the value in binary to the pipe
int length = strlen(argv[i]);
write(fd[i][1], &length, sizeof(int));
// Close the pipe since we are done with it.
Close(fd[i][1]);
exit(0);
} else {
// In the parent, but before doing the next loop iteration,
// close the end of the pipe that we don't want open
Close(fd[i][1]);
}
}
// Only the parent gets here
int sum = 0;
for (int i = 1; i < argc; i++) {
// Read one integer from each child
read(fd[i][0], &one_value, sizeof(int));
printf("I just read %d from pipe %d\n", one_value, i);
sum += one_value;
}
printf("Sum is %d\n", sum);
return 0;
} | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-10T21:01:58.427Z | General Question | v2 | STDIN_FILENO what is that | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-10T21:01:58.737Z | General Question | v2 | STDIN_FILENO what is that | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-10T22:04:12.758Z | General Question | v2 | what is excel | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-10T22:04:34.780Z | General Question | v2 | excel() funtion | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-10T22:05:10.125Z | General Question | v2 | execl() what is it? | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-10T22:14:36.624Z | General Question | v2 | how does dup2 work | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-10T22:48:22.949Z | General Question | v2 | what are argyments to pipe | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-13T23:35:58.059Z | General Question | v2 | how to check if a file in a directory exists? | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-13T23:51:59.226Z | General Question | v2 | how are makefiles evaluated | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-14T00:25:37.580Z | General Question | v2 | can you use printf on an array of char pointers? | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-14T00:34:32.988Z | General Question | v2 | how does execvp work | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-14T04:06:49.914Z | General Question | v2 | how to use stat to get the last modified time of a file | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-14T05:05:49.785Z | General Question | v2 | what is struct timespec; | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-14T15:03:24.946Z | General Question | v2 | how do I use the tv_sec member of stat.st_mtim? | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-27T21:13:20.431Z | Question from Code | v2 | what is this code chunk doing | // Set the IP and port of the server to connect to.
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
if (inet_pton(AF_INET, "127.0.0.1", &server.sin_addr) < 1) {
perror("client: inet_pton");
close(sock_fd);
exit(1);
} | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-30T02:59:13.310Z | General Question | v2 | explain asprintf and snprintf and their differences | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-03-30T03:20:13.028Z | General Question | v2 | what are the arguments to asprintf() | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-04-01T15:28:44.329Z | General Question | v2 | I want to dynamically alocate a string that keeps appending charcters to the buffer with asprintf() | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-04-01T15:48:09.863Z | General Question | v2 | is there a way to use asprintf and continually append to the same character buffer? | null | null | null |
63c647e85f004bf4898cf7b1 | 2023-04-03T00:44:15.702Z | Explain Code | v2 | null | struct sockaddr_in *init_server_addr(int port) {
struct sockaddr_in *addr = malloc(sizeof(struct sockaddr_in));
// Allow sockets across machines.
addr->sin_family = AF_INET;
// The port the process will listen on.
addr->sin_port = htons(port);
// Clear this field; sin_zero is used for padding for the struct.
memset(&(addr->sin_zero), 0, 8);
// Listen on all network interfaces.
addr->sin_addr.s_addr = INADDR_ANY;
return addr;
} | null | null |
63c647e85f004bf4898cf7b1 | 2023-04-03T00:46:17.586Z | Question from Code | v2 | why is this in a function | struct sockaddr_in *init_server_addr(int port) {
struct sockaddr_in *addr = malloc(sizeof(struct sockaddr_in));
// Allow sockets across machines.
addr->sin_family = AF_INET;
// The port the process will listen on.
addr->sin_port = htons(port);
// Clear this field; sin_zero is used for padding for the struct.
memset(&(addr->sin_zero), 0, 8);
// Listen on all network interfaces.
addr->sin_addr.s_addr = INADDR_ANY;
return addr;
} | null | null |
63c647e85f004bf4898cf7b1 | 2023-04-03T01:15:33.841Z | Explain Code | v2 | null | int accept_connection(int listenfd) {
struct sockaddr_in peer;
unsigned int peer_len = sizeof(peer);
peer.sin_family = AF_INET;
fprintf(stderr, "Waiting for a new connection...\n");
int client_socket = accept(listenfd, (struct sockaddr *)&peer, &peer_len);
if (client_socket < 0) {
perror("accept");
return -1;
} else {
fprintf(stderr, "New connection accepted from %s:%d\n", inet_ntoa(peer.sin_addr), ntohs(peer.sin_port));
return client_socket;
}
} | null | null |
63c647e85f004bf4898cf7b1 | 2023-04-03T22:03:03.499Z | Explain Code | v2 | null | while (fgets(input, INPUT_BUFFER_SIZE, input_stream) != NULL) {
// only echo the line in batch mode since in interactive mode the user
// just typed the line
if (batch_mode) {
printf("%s", input);
}
char *cmd_argv[INPUT_ARG_MAX_NUM];
int cmd_argc = tokenize(input, cmd_argv);
if (cmd_argc > 0 && process_args(cmd_argc, cmd_argv, &user_list) == -1) {
break; // can only reach if quit command was entered
}
printf("> ");
} | null | null |
63c647e85f004bf4898cf7b1 | 2023-04-03T22:15:15.298Z | Explain Code | v2 | null | int main(int argc, char *argv[]) {
int batch_mode = (argc == 2);
char input[INPUT_BUFFER_SIZE];
FILE *input_stream;
// Create the heads of the empty data structure
User *user_list = NULL;
if (batch_mode) {
input_stream = fopen(argv[1], "r");
if (input_stream == NULL) {
perror("Error opening file");
exit(1);
}
} else {
// interactive mode
input_stream = stdin;
}
printf("Welcome to FriendMe! (Local version)\nPlease type a command:\n> ");
while (fgets(input, INPUT_BUFFER_SIZE, input_stream) != NULL) {
// only echo the line in batch mode since in interactive mode the user
// just typed the line
if (batch_mode) {
printf("%s", input);
}
char *cmd_argv[INPUT_ARG_MAX_NUM];
int cmd_argc = tokenize(input, cmd_argv);
if (cmd_argc > 0 && process_args(cmd_argc, cmd_argv, &user_list) == -1) {
break; // can only reach if quit command was entered
}
printf("> ");
}
if (batch_mode) {
fclose(input_stream);
}
return 0;
} | null | null |
63c647e85f004bf4898cf7b1 | 2023-04-25T14:33:59.897Z | Explain Code | v2 | null | upper=$1
#we need the double quotes in case the filename has a space
filename="$2"
for i in `seq 1 $upper`
do
#note that we need to double quotes here as well around filename
if /u/csc209h/winter/pub/shell-prog/floop $i "$filename" > /dev/null
then
echo $i and $filename are a floopy combination
fi
done | null | null |
63c647e85f004bf4898cf7b1 | 2023-04-25T14:34:43.138Z | Explain Code | v2 | null | upper=$1
#we need the double quotes in case the filename has a space
filename="$2"
for i in `seq 1 $upper`
do
#note that we need to double quotes here as well around filename
if /u/csc209h/winter/pub/shell-prog/floop $i "$filename" > /dev/null
then
echo $i and $filename are a floopy combination
fi
done | null | null |
63c647e85f004bf4898cf7b6 | 2023-01-18T16:19:41.036Z | Explain Code | v1 | null | int i;
while((scanf(%d), i) != EOF){
} | null | null |
63c647e85f004bf4898cf7b6 | 2023-01-18T16:20:25.876Z | Explain Code | v1 | null | int i;
while((scanf(%d), i) != EOF){
printf(i)
} | null | null |
63c647e85f004bf4898cf7b6 | 2023-02-04T23:08:25.396Z | Explain Code | v1 | null | NumberOfElements = sizeof(arr)/sizeof(arr[0]); | null | null |
63c647e85f004bf4898cf7b6 | 2023-02-07T00:49:08.765Z | Help Fix Code | v1 | null | int print_user(const User *user) {
// characters to get from file
char line[81];
FILE *pfp;
// int error;
int valid_pfp = 1; // checks if pfp can be accessed
// checks if user doesn't exist
if (user == NULL) {
return 1;
}
// checking if error opening file
pfp = fopen(user->profile_pic, "r");
if (pfp == NULL){
valid_pfp = 0;
}
// print everything, skip profile picture if error with opening
if (valid_pfp) {
// print profile picture
while (fgets(line, 81, pfp) != NULL){
printf("%s", line);
}
// close file after use
fclose(pfp);
printf("\n");
}
printf("Name: %s\n", user->name);
printf("------------------------------------------\n");
printf("Friends:\n");
// print out friends
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");
Post *curr = user->first_post;
if (curr != NULL){
while (curr->next != NULL){
printf("From: %s\n", curr->author);
printf("Date: %s\n", ctime(curr->date));
printf("%s\n", curr->contents);
printf("\n");
printf("===\n");
printf("\n");
curr = curr->next;
}
printf("From: %s\n", curr->author);
printf("Date: %s\n", ctime(curr->date));
printf("%s\n", curr->contents);
}
printf("------------------------------------------\n");
return 0;
} | print user information, fix set fault | null |
63c647e85f004bf4898cf7b6 | 2023-02-07T00:50:26.800Z | Help Fix Code | v1 | null | int print_user(const User *user) {
// characters to get from file
char line[81];
FILE *pfp;
// int error;
int valid_pfp = 1; // checks if pfp can be accessed
// checks if user doesn't exist
if (user == NULL) {
return 1;
}
// checking if error opening file
pfp = fopen(user->profile_pic, "r");
if (pfp == NULL){
valid_pfp = 0;
}
// print everything, skip profile picture if error with opening
if (valid_pfp) {
// print profile picture
while (fgets(line, 81, pfp) != NULL){
printf("%s", line);
}
// close file after use
fclose(pfp);
printf("\n");
}
printf("Name: %s\n", user->name);
printf("------------------------------------------\n");
printf("Friends:\n");
// print out friends
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");
Post *curr = user->first_post;
if (curr != NULL){
while (curr->next != NULL){
printf("From: %s\n", curr->author);
printf("Date: %s\n", ctime(curr->date));
printf("%s\n", curr->contents);
printf("\n");
printf("===\n");
printf("\n");
curr = curr->next;
}
printf("From: %s\n", curr->author);
printf("Date: %s\n", ctime(curr->date));
printf("%s\n", curr->contents);
}
printf("------------------------------------------\n");
return 0;
} | segmentation fault | null |
63c647e85f004bf4898cf7b6 | 2023-03-12T00:05:02.534Z | Help Fix Code | v2 | recursively run the function
| Dependency *curr_dep = rule_eval->dependencies;
while (curr_dep != NULL) {
// evaluate dependencies
if (curr_dep->rule->actions != NULL) {
if (stat(rule_eval->target, &target_time) == -1){
run_make(curr_dep->rule->target, rules, pflag);
}
else {
// check times
printf("FOUND FILE\n");
if (stat(curr_dep->rule->target, &dep_time) == -1) {
perror("stat");
exit(1);
}
if (dep_time.st_mtim.tv_sec >= target_time.st_mtim.tv_sec) {
if (dep_time.st_mtim.tv_nsec > target_time.st_mtim.tv_nsec) {
run_make(curr_dep->rule->target, rules, pflag);
}
}
}
}
curr_dep = curr_dep->next_dep;
}
// execute actions
pid_t ret = fork();
if (ret < 0) {
perror("fork");
exit(1);
}
else if (ret == 0) {
char *cmd = (rule_eval->actions->args)[0];
int error = execvp(cmd, rule_eval->actions->args);
if (error == -1) {
exit(1);
}
}
else {
int status;
wait(&status);
if (WIFEXITED(status)) {
exit(1);
}
return;
}
| null | null |
63c647e85f004bf4898cf7b6 | 2023-03-23T15:56:52.944Z | Explain Code | v2 | null | while (1) {
fd_set listen_fds = all_fds;
if (select(max_fd + 1, &listen_fds, NULL, NULL, NULL) == -1) {
perror("server: select");
exit(1);
}
if (FD_ISSET(sock_fd, &listen_fds)) {
int client_fd = accept_connection(sock_fd, users);
if (client_fd > max_fd) {
max_fd = client_fd;
}
FD_SET(client_fd, &all_fds);
printf("Accepted connection\n");
}
for (int index = 0; index < MAX_CONNECTIONS; index++) {
if (users[index].sock_fd > -1 && FD_ISSET(users[index].sock_fd, &listen_fds)) {
int client_closed = read_from(index, users);
if (client_closed > 0) {
FD_CLR(client_closed, &all_fds);
printf("Client %d disconnected\n", client_closed);
} else {
printf("Echoing message from client %d\n", users[index].sock_fd);
}
}
}
} | null | null |
63c647e85f004bf4898cf7b6 | 2023-03-25T17:45:17.929Z | General Question | v2 | when using asprintf multiple times with the same buffer is it neccessary to free memory multiple times or just once at the end | null | null | null |
63c647e95f004bf4898cf7bb | 2023-01-27T00:14:51.146Z | Help Fix Code | v1 | null | int **split_array(const int *s, int length) {
int num_evens;
int num_odds = length / 2;
if (length % 2 == 0){
num_evens = length / 2;
} else{
num_evens = (length / 2) + 1;
}
int *array1 = malloc(sizeof(int) * num_evens);
int *array2 = malloc(sizeof(int) * num_odds);
int count1 = 0;
int count2 = 0;
for (int i = 0; i < length; i++){
if (i % 2 == 0){
array1[count1] = s[i];
count1 = count1 + 1;
} else{
array2[count2] = s[i];
count2 = count2 + 1;
}
}
//int **arrays_ptr = malloc(sizeof(int*) * 2);
// Not stored in heap since itself is not, but it consists of 2 dynamically allocatted arrays of ints
int *arrays_ptr[2];
arrays_ptr[0] = array1;
arrays_ptr[1] = array2;
return arrays_ptr;
} | return int ** | null |
63c647e95f004bf4898cf7bb | 2023-01-27T00:19:15.402Z | General Question | v1 | how to declare a pointer to point to dynamically allocated arrays | null | null | null |
63c647e95f004bf4898cf7bb | 2023-01-27T00:34:13.410Z | General Question | v1 | how to access elements from a pointer that points to an array | null | null | null |
63c647e95f004bf4898cf7bb | 2023-01-27T01:12:25.102Z | General Question | v1 | how to store something on the heap | null | null | null |
63c647e95f004bf4898cf7bb | 2023-01-27T01:12:44.540Z | General Question | v1 | how to store an array on the heap | null | null | null |
63c647e95f004bf4898cf7bb | 2023-01-27T16:32:39.122Z | Help Fix Code | v1 | null | int **split_array(const int *s, int length) {
int num_evens;
int num_odds = length / 2;
if (length % 2 == 0){
num_evens = length / 2;
} else{
num_evens = (length / 2) + 1;
}
printf("OMG: %d\n", s[0]);
printf("OMG: %d\n", s[1]);
printf("OMG: %d\n", s[2]);
int *array1 = malloc(sizeof(int) * num_evens);
int *array2 = malloc(sizeof(int) * num_odds);
int count1 = 0;
int count2 = 0;
printf("OMG2: %d\n", s[0]);
printf("OMG2: %d\n", s[1]);
printf("OMG2: %d\n", s[2]);
printf("evens: %d odds: %d\n", num_evens, num_odds);
for (int i = 0; i < length; i++){
printf("HERRRRE: %d\n", s[i]);
if (i % 2 == 0){
array1[count1] = s[i];
count1 = count1 + 1;
//printf("HERRRRE: %d\n", s[i]);
} else{
array2[count2] = s[i];
count2 = count2 + 1;
//printf("OK: %d\n", s[i]);
}
}
int **arrays_ptr = malloc(sizeof(int *) * 2);
// Not stored in heap since itself is not, but it consists of 2 dynamically allocatted arrays of ints
//int *arrays_ptr[2];
arrays_ptr[0] = array1;
arrays_ptr[1] = array2;
return arrays_ptr;
} | why is s being changed? | null |
63c647e95f004bf4898cf7bb | 2023-01-27T16:33:43.167Z | Help Fix Code | v1 | null | int **split_array(const int *s, int length) {
int num_evens;
int num_odds = length / 2;
if (length % 2 == 0){
num_evens = length / 2;
} else{
num_evens = (length / 2) + 1;
}
int *array1 = malloc(sizeof(int) * num_evens);
int *array2 = malloc(sizeof(int) * num_odds);
int count1 = 0;
int count2 = 0;
for (int i = 0; i < length; i++){
if (i % 2 == 0){
array1[count1] = s[i];
count1 = count1 + 1;
} else{
array2[count2] = s[i];
count2 = count2 + 1;
}
}
int **arrays_ptr = malloc(sizeof(int *) * 2);
// Not stored in heap since itself is not, but it consists of 2 dynamically allocatted arrays of ints
//int *arrays_ptr[2];
arrays_ptr[0] = array1;
arrays_ptr[1] = array2;
return arrays_ptr;
} | is s being changed? | null |
63c647e95f004bf4898cf7bb | 2023-01-27T16:34:59.458Z | Help Fix Code | v1 | null | int **split_array(const int *s, int length) {
int num_evens;
int num_odds = length / 2;
if (length % 2 == 0){
num_evens = length / 2;
} else{
num_evens = (length / 2) + 1;
}
int *array1 = malloc(sizeof(int) * num_evens);
int *array2 = malloc(sizeof(int) * num_odds);
int count1 = 0;
int count2 = 0;
for (int i = 0; i < length; i++){
if (i % 2 == 0){
array1[count1] = s[i];
count1 = count1 + 1;
} else{
array2[count2] = s[i];
count2 = count2 + 1;
}
}
int **arrays_ptr = malloc(sizeof(int *) * 2);
// Not stored in heap since itself is not, but it consists of 2 dynamically allocatted arrays of ints
//int *arrays_ptr[2];
arrays_ptr[0] = array1;
arrays_ptr[1] = array2;
return arrays_ptr;
} | s does not change | null |
63c647e95f004bf4898cf7bb | 2023-01-27T16:35:18.065Z | Question from Code | v1 | does s change? | int **split_array(const int *s, int length) {
int num_evens;
int num_odds = length / 2;
if (length % 2 == 0){
num_evens = length / 2;
} else{
num_evens = (length / 2) + 1;
}
int *array1 = malloc(sizeof(int) * num_evens);
int *array2 = malloc(sizeof(int) * num_odds);
int count1 = 0;
int count2 = 0;
for (int i = 0; i < length; i++){
if (i % 2 == 0){
array1[count1] = s[i];
count1 = count1 + 1;
} else{
array2[count2] = s[i];
count2 = count2 + 1;
}
}
int **arrays_ptr = malloc(sizeof(int *) * 2);
// Not stored in heap since itself is not, but it consists of 2 dynamically allocatted arrays of ints
//int *arrays_ptr[2];
arrays_ptr[0] = array1;
arrays_ptr[1] = array2;
return arrays_ptr;
} | null | null |
63c647e95f004bf4898cf7bb | 2023-01-27T16:35:48.105Z | Question from Code | v1 | what are the values of s in the beginning? | int **split_array(const int *s, int length) {
int num_evens;
int num_odds = length / 2;
if (length % 2 == 0){
num_evens = length / 2;
} else{
num_evens = (length / 2) + 1;
}
int *array1 = malloc(sizeof(int) * num_evens);
int *array2 = malloc(sizeof(int) * num_odds);
int count1 = 0;
int count2 = 0;
for (int i = 0; i < length; i++){
if (i % 2 == 0){
array1[count1] = s[i];
count1 = count1 + 1;
} else{
array2[count2] = s[i];
count2 = count2 + 1;
}
}
int **arrays_ptr = malloc(sizeof(int *) * 2);
// Not stored in heap since itself is not, but it consists of 2 dynamically allocatted arrays of ints
//int *arrays_ptr[2];
arrays_ptr[0] = array1;
arrays_ptr[1] = array2;
return arrays_ptr;
} | null | null |
63c647e95f004bf4898cf7bb | 2023-01-27T16:36:13.693Z | Question from Code | v1 | should s change at the end of the code? | int **split_array(const int *s, int length) {
int num_evens;
int num_odds = length / 2;
if (length % 2 == 0){
num_evens = length / 2;
} else{
num_evens = (length / 2) + 1;
}
int *array1 = malloc(sizeof(int) * num_evens);
int *array2 = malloc(sizeof(int) * num_odds);
int count1 = 0;
int count2 = 0;
for (int i = 0; i < length; i++){
if (i % 2 == 0){
array1[count1] = s[i];
count1 = count1 + 1;
} else{
array2[count2] = s[i];
count2 = count2 + 1;
}
}
int **arrays_ptr = malloc(sizeof(int *) * 2);
// Not stored in heap since itself is not, but it consists of 2 dynamically allocatted arrays of ints
//int *arrays_ptr[2];
arrays_ptr[0] = array1;
arrays_ptr[1] = array2;
return arrays_ptr;
} | null | null |
63c647e95f004bf4898cf7bb | 2023-01-27T16:36:44.173Z | Question from Code | v1 | where is s, array1, and array2 stored? | int **split_array(const int *s, int length) {
int num_evens;
int num_odds = length / 2;
if (length % 2 == 0){
num_evens = length / 2;
} else{
num_evens = (length / 2) + 1;
}
int *array1 = malloc(sizeof(int) * num_evens);
int *array2 = malloc(sizeof(int) * num_odds);
int count1 = 0;
int count2 = 0;
for (int i = 0; i < length; i++){
if (i % 2 == 0){
array1[count1] = s[i];
count1 = count1 + 1;
} else{
array2[count2] = s[i];
count2 = count2 + 1;
}
}
int **arrays_ptr = malloc(sizeof(int *) * 2);
// Not stored in heap since itself is not, but it consists of 2 dynamically allocatted arrays of ints
//int *arrays_ptr[2];
arrays_ptr[0] = array1;
arrays_ptr[1] = array2;
return arrays_ptr;
} | null | null |
63c647e95f004bf4898cf7bb | 2023-01-27T16:40:49.572Z | Help Write Code | v1 | null | null | null | write code to 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. |
63c647e95f004bf4898cf7bb | 2023-01-27T16:45:00.905Z | Explain Code | v1 | null | int **split_array(const int *s, int length) {
int num_evens;
int num_odds = length / 2;
if (length % 2 == 0){
num_evens = length / 2;
} else{
num_evens = (length / 2) + 1;
}
int *array1 = malloc(sizeof(int) * num_evens);
int *array2 = malloc(sizeof(int) * num_odds);
int count1 = 0;
int count2 = 0;
for (int i = 0; i < length; i++){
if (i % 2 == 0){
array1[count1] = s[i];
count1 = count1 + 1;
} else{
array2[count2] = s[i];
count2 = count2 + 1;
}
}
int **arrays_ptr = malloc(sizeof(int *) * 2);
// Not stored in heap since itself is not, but it consists of 2 dynamically allocatted arrays of ints
//int *arrays_ptr[2];
arrays_ptr[0] = array1;
arrays_ptr[1] = array2;
return arrays_ptr;
} | null | null |
63c647e95f004bf4898cf7bb | 2023-02-02T05:49:18.409Z | General Question | v1 | How do you declare an array of chars? | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-02T05:49:51.132Z | General Question | v1 | how do you declare an array of chars of unknown size? | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-02T06:12:04.315Z | General Question | v1 | How to copy a string to an empty string | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-02T06:12:54.022Z | General Question | v1 | How to declare empty string as destination string to for strcpy? | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-10T03:49:26.682Z | General Question | v1 | How to allocate space for 5 `struct pixel *` values | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-10T04:12:06.097Z | General Question | v1 | How to store two dimensional array on heap | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-10T04:12:41.563Z | General Question | v1 | What is code to store two dimensional array on heap | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-14T06:14:04.622Z | General Question | v1 | How to declare a pointer to the current date? | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-14T06:14:41.139Z | General Question | v1 | How to get the current date? | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-14T11:41:00.472Z | General Question | v1 | #define MAXNAME = 32;
and then the declaration
char name[MAXNAME];
What will this declaration line become after the program has passed
through the C pre-processor? | null | null | null |
63c647e95f004bf4898cf7bb | 2023-02-14T11:42:04.108Z | Question from Code | v1 | What will the declaration on line 2 become after the program has passed through the C pre-processor? | #define MAXNAME = 32;
char name[MAXNAME]; | null | null |
63c647e95f004bf4898cf7bb | 2023-02-14T11:47:12.002Z | Question from Code | v1 | What is the output? | #define SUPERVISOR(regular) regular + 5
int main() {
int regular_pay = 20;
int hours_worked = 10;
printf("pay is %d\n", (hours_worked * SUPERVISOR(regular_pay)));
// rest omitted
} | null | null |
63c647e95f004bf4898cf7bb | 2023-02-14T11:48:23.535Z | Question from Code | v1 | What is the output? | #define SUPERVISOR(regular) regular + 5
#define SUPERVISOR(regular) regular + 5
int main() {
int regular_pay = 20;
int hours_worked = 10;
printf("pay is %d\n", (hours_worked * SUPERVISOR(regular_pay)));
// rest omitted
} | null | null |
63c647e95f004bf4898cf7c0 | 2023-01-17T15:52:51.674Z | General Question | v1 | how to declare strings | null | null | null |
63c647e95f004bf4898cf7c0 | 2023-02-09T04:57:13.776Z | Question from Code | v1 | why is it causing segmentation fault while I run it?
| struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) {
struct pixel ** my_pixels = malloc(sizeof(struct pixel *) * height);
// initialize it to point for an entire row of pixel data
for(int i = 0; i < height; i++){
my_pixels[i] = malloc(sizeof(struct pixel *) * width);
}
// fill it with data
//
fseek(image, pixel_array_offset, SEEK_SET);
int val = fread(my_pixels, sizeof(struct pixel), height*width, image);
printf("%d\n", val);
return my_pixels;
} | null | null |
63c647e95f004bf4898cf7c0 | 2023-02-09T04:58:20.096Z | General Question | v1 | how to use fread? | null | null | null |
63c647e95f004bf4898cf7c0 | 2023-02-09T05:41:16.261Z | General Question | v1 | using SEEK_CUR of fread | null | null | null |
63c647e95f004bf4898cf7c0 | 2023-02-26T20:30:21.303Z | General Question | v1 | How can I use the line of a file as the arguments to my c program in a shell script
| null | null | null |
63c647e95f004bf4898cf7c0 | 2023-02-26T21:29:28.680Z | Help Fix Code | v1 | null | #include <stdio.h>
#include <string.h>
int main(){
char * my_string;
char * second_one = "hola mundo";
strcpy(my_string, second_one);
printf("%s\n", my_string);
return 0;
} | copy the contents of second_one into my_string | null |
63c647e95f004bf4898cf7c0 | 2023-03-15T06:01:01.630Z | Help Fix Code | v2 | if the file exists set target_time to the st_mtime which is a struct | struct stat sb;
struct stat sb_dep;
struct timespec * target_time = NULL;
struct timespec dependency_time;
int status;
if(access(target, F_OK) == 0){
if (stat(target, &sb) == -1) {
perror("stat");
exit(1);
}
printf("line test\n");
*(target_time) = sb.st_mtim;
} | null | null |
63c647e95f004bf4898cf7c0 | 2023-03-15T06:03:35.314Z | Help Write Code | v2 | null | null | null | how to use struct timespec st_mtim; to get the most recent file between two files |
63c647ea5f004bf4898cf7c5 | 2023-02-10T21:26:59.270Z | General Question | v1 | What is Fseek
| null | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-11T04:03:12.911Z | General Question | v1 | how to open a file
| null | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-11T04:04:23.389Z | General Question | v1 | how to check if opening file caused error | null | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-11T04:05:47.378Z | General Question | v1 | read contents in a file
| null | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-13T23:45:17.132Z | Question from Code | v1 | is there a segmentation fault here | FILE *picture = fopen(user->profile_pic, "r"); | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-13T23:46:11.996Z | Question from Code | v1 | what if user is a valid pointer to a struct with an attribute profile_pic | FILE *picture = fopen(user->profile_pic, "r"); | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-13T23:47:07.263Z | Help Fix Code | v1 | null | if (user->profile_pic != NULL){
FILE *picture = fopen(user->profile_pic, "r");
if (picture != NULL){
char line[32];
while(fgets(line, sizeof(line), picture) != NULL){
printf("%s\n", line);
}
}
fclose(picture);
} | Supposed to read the contents in the file picture and print it | null |
63c647ea5f004bf4898cf7c5 | 2023-02-13T23:49:51.804Z | General Question | v1 | ==41828== Syscall param openat(filename) points to uninitialised byte(s)
what does this mean | null | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-13T23:51:02.012Z | Question from Code | v1 | Fix this error Syscall param openat(filename) points to uninitialised byte(s) | if (user->profile_pic != NULL){
FILE *picture = fopen(user->profile_pic, "r");
if (picture != NULL){
char line[32];
while(fgets(line, sizeof(line), picture) != NULL){
printf("%s\n", line);
}
fclose(picture);
}
} | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T00:02:24.147Z | Question from Code | v1 | Does it matter if I read the file in chunks of 32 bits | if (user->profile_pic != NULL){
FILE *picture = fopen(user->profile_pic, "r");
if (picture != NULL){
char line[32];
while(fgets(line, sizeof(line), picture) != NULL){
printf("%s\n", line);
}
fclose(picture);
}
} | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T00:03:04.530Z | Question from Code | v1 | Should I change the fgets to 1 bit | if (user->profile_pic != NULL){
FILE *picture = fopen(user->profile_pic, "r");
if (picture != NULL){
char line[32];
while(fgets(line, sizeof(line), picture) != NULL){
printf("%s\n", line);
}
fclose(picture);
}
} | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T00:04:59.180Z | General Question | v1 | If I do not know the number of characters in a file, but need to use fgets. What should the second parameter be | null | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T04:38:25.097Z | Question from Code | v1 | I dont see why I am getting a Invalid read of size 8 error on line 8 | User *curr = (User*) target->friends;
int friends = 0;
while (curr != NULL){
// Boolean = 1 if they are friends
if (strcmp(author->name, target->name) == 0/){
friends = 1;
}
curr = curr->next;
} | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T04:54:04.779Z | Help Fix Code | v1 | null | new_post->next = target->first_post;
target->first_post = new_post; | I am supposed to put new_post in the beginning of the target->first_post and I need help with malloc | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T05:01:10.771Z | Help Fix Code | v1 | null | // Put post at front
if (target->first_post == NULL){
target->first_post = malloc(sizeof(Post));
target->first_post = new_post;
}
else{
Post *curr_first = (Post*) malloc(sizeof(Post));
curr_first = target->first_post;
target->first_post = new_post;
target->first_post->next = curr_first;
} | This is causing the new post to be added countless times | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T05:04:04.957Z | Help Fix Code | v1 | null | // Put post at front
if (target->first_post == NULL){
target->first_post = new_post;
}
else{
Post *curr_first = target->first_post;
target->first_post = new_post;
target->first_post->next = curr_first;
} | I want it to add the new post at the beginning of the target->first_post | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T05:09:54.000Z | Explain Code | v1 | null | // Assign space for new post
Post *new_post = (Post*) malloc(sizeof(Post));
// Initialize poster
strncpy(new_post->author, author->name, MAX_NAME - 1);
new_post->author[MAX_NAME-1] = '\0';
// Initialize content
new_post->contents = malloc(sizeof(contents)) ;
long size_content = strlen(contents);
strncpy(new_post->contents, contents, size_content - 1);
new_post->contents[size_content - 1] = '\0';
// Initialize date
time_t *current_time = malloc(sizeof(time_t));
time(current_time);
new_post->date = current_time;
// Put post at front
if (target->first_post == NULL){
target->first_post = new_post;
}
else{
Post *curr_first = target->first_post;
new_post -> next = curr_first;
target->first_post = new_post;
}
return 0; | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T05:12:12.011Z | Help Fix Code | v1 | null | // Assign space for new post
Post *new_post = (Post*) malloc(sizeof(Post));
// Initialize poster
strncpy(new_post->author, author->name, MAX_NAME - 1);
new_post->author[MAX_NAME-1] = '\0';
// Initialize content
new_post->contents = malloc(sizeof(contents)) ;
long size_content = strlen(contents);
strncpy(new_post->contents, contents, size_content - 1);
new_post->contents[size_content - 1] = '\0';
// Initialize date
time_t *current_time = malloc(sizeof(time_t));
time(current_time);
new_post->date = current_time;
// Put post at front
if (target->first_post == NULL){
target->first_post = new_post;
}
else{
Post *curr_first = target->first_post;
new_post -> next = curr_first;
target->first_post = new_post;
}
return 0; | The code above creates a new post, initializes its author, contents, and date, and then puts the post at the front of the list of posts for the target user. | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T05:14:30.751Z | General Question | v1 | how do I print a time_t data | null | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T05:15:04.578Z | General Question | v1 | print from a time_t * | null | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T05:19:51.479Z | Explain Code | v1 | null | /printf("Posts:\n");
Post *curr = user->first_post;
while (curr != NULL){
printf("From: %s\n", curr->author);
printf("Date: %s\n", ctime(curr->date));
printf("\n");
printf("%s\n", curr->contents);
if (curr->next != NULL){
printf("\n");
printf("===");
printf("\n");
}
} | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T06:02:31.007Z | Question from Code | v1 | Why am I getting a curr may not be initialized error | // Print post list
printf("Posts:\n");
Post *curr = user->first_post;
while (curr != NULL){
printf("From: %s\n", curr->author);
printf("Date: %s\n", ctime(curr->date));
printf("%s\n", curr->contents);
if (curr->next != NULL){
printf("\n");
printf("===");
printf("\n");
}
curr = curr->next;
}
printf("------------------------------------------\n");
| null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T06:03:24.469Z | General Question | v1 | How do I use calloc | null | null | null |
63c647ea5f004bf4898cf7c5 | 2023-02-14T07:13:07.158Z | Question from Code | v1 | Can you spot the conditional move depends on uninitialized error here | if (user->first_post){
curr = user->first_post;
}
while (curr != NULL){
if (curr != user->first_post){
printf("\n");
printf("===\n");
printf("\n");
}
printf("From: %s\n", curr->author);
printf("Date: %s\n", ctime(curr->date));
printf("%s\n", curr->contents);
curr = curr->next;
}
printf("------------------------------------------\n"); | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.