Student question: How to fix printf("[Server]"); such that only [server] is printed?

Question: How to fix printf("[Server]"); such that only [server] is printed?


Student question: Why does it say ‘temp2’ may be used uninitialized in this function line 227? | Code context (simplify for kids): char *temp2; 226 for (int i = 0; i < MAX_FRIENDS && user->friends[i] != NULL; i++) { 227 snprintf(temp2, strlen(user->friends[i]->name + 2), "%s\r\n", user->friends[i]->name); }

Question: Why does it say ‘temp2’ may be used uninitialized in this function line 227?


Student question: Why is it printing 0? | Code context (simplify for kids): char *user_string = calloc(sizeof(char) * 171, 1); printf("%ld\n", strlen(user_string));

Question: Why is it printing 0?


Student question: Why is this code not copying name, friends and posts into user_string? | Code context (simplify for kids): snprintf(user_string, sizeof(user), "%s%s%s", name, friends, posts);

Question: Why is this code not copying name, friends and posts into user_string?


Code context (simplify for kids): int main(int argc, char *argv[]) { 145 int batch_mode = (argc == 2); 146 char input[INPUT_BUFFER_SIZE]; 147 FILE *input_stream; 148 149 150 User *user_list = NULL; 151 152 if (batch_mode) { 153 input_stream = fopen(argv[1], "r"); 154 if (input_stream == NULL) { 155 perror("Error opening file"); 156


Task: How can I add code to make this a server where other clients can connect to it?


Code context (simplify for kids): int main() { setbuf(stdout, NULL); struct sockaddr_in *self = init_server_addr(PORT); int listenfd = set_up_server_socket(self, 5); while (1) { int fd = accept_connection(listenfd); if (fd < 0) { continue; } char buf[BUFSIZE] = {'\0'}; int inbuf = 0; int room = sizeof(buf); char *after = buf; int nb


Student question: How do I change (what do I add, where should I add them, and what should I remove) from this code if I want to change it from local host to hosting on a server? | Code context (simplify for kids): main{ 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 { // intera

Question: How do I change (what do I add, where should I add them, and what should I remove) from this code if I want to change it from local host to hosting on a server?


Student question: How to solve this two errors? friend_server.c:22:25: error: expected expression before ‘[’ token 22 | int status = setsockopt([sock_fd], SOL_SOCKET, SO_REUSEADDR, | ^ friend_server.c:22:26: error: ‘sock_fd’ undeclared here (not in a function) 22 | int status = setsockopt([sock_fd], SOL_SOCKET, SO_REUSEADDR,

Question: How to solve this two errors? friend_server.c:22:25: error: expected expression before ‘[’ token 22 | int status = setsockopt([sock_fd], SOL_SOCKET, SO_REUSEADDR, | ^ friend_server.c:22:26: error: ‘sock_fd’ undeclared here (not in a function) 22 | int status = setsockopt([sock_fd], SOL_SOCKET, SO_REUSEADDR,


Student question: what is the sock fd in this code? | Code context (simplify for kids): int listen_soc = socket(AF_INET, SOCK_STREAM, 0); if (listen_soc == -1) { perror("server: socket"); exit(1); } struct sockaddr_in server; server.sin_family = AF_INET; server.sin_port = htons(54321); memset(&server.sin_zero, 0, 8); server.sin_addr.s_addr = INADDR_ANY; if (bind(listen_soc, (struct soc

Question: what is the sock fd in this code?


Student question: How to fix this error error: ‘g’ undeclared (first use in this function) friend_server.c:160:29: note: in expansion of macro ‘PORT’ 160 | server.sin_port = htons(PORT); | ^~~~ <command-line>: note: each undeclared identifier is reported only once for each function it appears in friend_server.c:160:29: note: in expansion of macro ‘PORT’ 160 | server.sin_port = htons(PORT); | ^~~~ | Code context (simplify for kids): // Create socket int listen_soc = socket(AF_INET, SOCK_STREAM, 0); if (listen_soc == -1) { perror("server: socket"); exit(1); } //initialize server address struct sockaddr_in server; server.sin_family = AF_INET; server.sin_port = htons(PORT); memset(&server.sin_zero, 0, 8); server.sin_addr.s_addr =

Question: How to fix this error error: ‘g’ undeclared (first use in this function) friend_server.c:160:29: note: in expansion of macro ‘PORT’ 160 | server.sin_port = htons(PORT); | ^~~~ <command-line>: note: each undeclared identifier is reported only once for each function it appears in friend_server.c:160:29: note: in expansion of macro ‘PORT’ 160 | server.sin_port = htons(PORT); | ^~~~


Code context (simplify for kids): int batch_mode = (argc == 2); char input[INPUT_BUFFER_SIZE]; FILE *input_stream; User *user_list = NULL; if (batch_mode) { input_stream = fopen(argv[1], "r"); if (input_stream == NULL) { perror("Error opening file"); exit(1); } } else { input_stream = stdin; } while (fgets(input, INPUT_BUFFER_SIZE,


Task: every time a client connects to a server, increment the client_count variable and change curr (which is a specific node in a linked list) to the new client.


Student question: How to fix this error: assignment to expression with array type 212 | curr->name = calloc(sizeof(char) * (MAX_NAME + 2), 1);

Question: How to fix this error: assignment to expression with array type 212 | curr->name = calloc(sizeof(char) * (MAX_NAME + 2), 1);


Code context (simplify for kids): while (fgets(input, INPUT_BUFFER_SIZE, input_stream) != NULL) { 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; }


Student question: How to change the code such that it prints out whether it is an old socket or new socket accordingly? | Code context (simplify for kids): 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); write(client_socket, "What is your user name?\n", 24); }

Question: How to change the code such that it prints out whether it is an old socket or new socket accordingly?


Student question: What is the difference between accept and accept connection in c?

Question: What is the difference between accept and accept connection in c?


Student question: How to fix this error? 'User’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror] 212 | void cleanup_args_for_processing(struct User *user_list, int client_fd)

Question: How to fix this error? 'User’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror] 212 | void cleanup_args_for_processing(struct User *user_list, int client_fd)


Student question: What is the problem with this? expected expression before ‘User’ 408 | check_and_add_user(User * user_list, int client_fd); | ^~~~ error: too few arguments to function ‘check_and_add_user’ 408 | check_and_add_user(User * user_list, int client_fd); | ^~~~~~~~~~~~~~~~~~ note: declared here 256 | void check_and_add_user(User *user_list, int client_fd)

Question: What is the problem with this? expected expression before ‘User’ 408 | check_and_add_user(User * user_list, int client_fd); | ^~~~ error: too few arguments to function ‘check_and_add_user’ 408 | check_and_add_user(User * user_list, int client_fd); | ^~~~~~~~~~~~~~~~~~ note: declared here 256 | void check_and_add_user(User *user_list, int client_fd)


Student question: Why is it asking for more arguments? function call: check_and_add_user(User *user_list, int client_fd); function header: 256 void check_and_add_user(User *user_list, int client_fd)

Question: Why is it asking for more arguments? function call: check_and_add_user(User *user_list, int client_fd); function header: 256 void check_and_add_user(User *user_list, int client_fd)


Student question: How to fix this error invalid type argument of ‘->’ (have ‘fd_set’ {aka ‘struct <anonymous>’}) 471 | if (curr_client->fd > -1 && FD_ISSET(curr_client->fd, listen_fds))

Question: How to fix this error invalid type argument of ‘->’ (have ‘fd_set’ {aka ‘struct <anonymous>’}) 471 | if (curr_client->fd > -1 && FD_ISSET(curr_client->fd, listen_fds))


Code context (simplify for kids): if (FD_ISSET(listen_soc, &listen_fds)) { client_fd = accept_connection(listen_soc, client_list); printf("main (test) client fd: %d\n", client_fd); if (client_fd == -1) { perror("accept"); return -1; } printf("clinet_fd: %d\n", client_fd); printf("max_fd: %d\n", max_fd); Client *client_ptr = find_cli


Student question: This code checks if a new connection has been made on the listening socket. If a new connection has been made, it accepts the connection and adds the new client to the client list. If the client is already in the list, it cleans up the arguments for processing. If the client is not in the list, it prompts the client for their username and adds the user to the user list. It then creates a new clien | Code context (simplify for kids): if (FD_ISSET(listen_soc, &listen_fds)) { client_fd = accept_connection(listen_soc, client_list); printf("main (test) client fd: %d\n", client_fd); if (client_fd == -1) { perror("accept"); return -1; } printf("clinet_fd: %d\n", client_fd); printf("max_fd: %d\n", max_fd); Client *client_ptr = find_cli

Question: This code checks if a new connection has been made on the listening socket. If a new connection has been made, it accepts the connection and adds the new client to the client list. If the client is already in the list, it cleans up the arguments for processing. If the client is not in the list, it prompts the client for their username and adds the user to the user list. It then creates a new clien


Student question: How to check if client is already in the list? | Code context (simplify for kids): if (FD_ISSET(listen_soc, &listen_fds)) { client_fd = accept_connection(listen_soc, client_list); printf("main (test) client fd: %d\n", client_fd); if (client_fd == -1) { perror("accept"); return -1; } printf("clinet_fd: %d\n", client_fd); printf("max_fd: %d\n", max_fd); Client *client_ptr = find_cli

Question: How to check if client is already in the list?


Student question: Why is my code running check_and_add_user even when the client already exist? | Code context (simplify for kids): if (FD_ISSET(listen_soc, &listen_fds)) { client_fd = accept_connection(listen_soc, client_list); printf("main (test) client fd: %d\n", client_fd); if (client_fd == -1) { perror("accept"); return -1; } printf("clinet_fd: %d\n", client_fd); printf("max_fd: %d\n", max_fd); Client *client_ptr = find_cli

Question: Why is my code running check_and_add_user even when the client already exist?


Student question: return a pointer to the Client structure that corresponds to the given file descriptor, or NULL if no such Client structure exists | Code context (simplify for kids): Client *find_client(int client_fd, const Client *head) { while (head != NULL && head->fd != client_fd) { head = head->next; } return (Client *)head; }

Question: return a pointer to the Client structure that corresponds to the given file descriptor, or NULL if no such Client structure exists


Student question: return a pointer to the Client structure that corresponds to the given file descriptor, or NULL if no such Client structure exists | Code context (simplify for kids): Client *find_client(int client_fd, const Client *client_list) { Client *curr = client_list; while (curr != NULL && curr->fd != client_fd) { curr = curr->next; } return (Client *)curr; }

Question: return a pointer to the Client structure that corresponds to the given file descriptor, or NULL if no such Client structure exists


Student question: Why does this not write even when there is a user->name that is equal name? | Code context (simplify for kids): while (curr->next != NULL) { if (strcmp(curr->name, name) == 0) { write(client_fd, "Welcome Back\n", 13); break; } curr = curr->next; }

Question: Why does this not write even when there is a user->name that is equal name?


Student question: how to set input stream as client_socket?

Question: how to set input stream as client_socket?


Student question: What would be the output if this function is ran on ("list_users", "")? | Code context (simplify for kids): int tokenize(char *cmd, char **cmd_argv) { int cmd_argc = 0; char *next_token = strtok(cmd, DELIM); while (next_token != NULL) { if (cmd_argc >= INPUT_ARG_MAX_NUM - 1) { error("Too many arguments!"); cmd_argc = 0; break; } cmd_argv[cmd_argc] = next_token; cmd_argc++; next_token = strtok(NULL, DELIM)

Question: What would be the output if this function is ran on ("list_users", "")?


Student question: why is strncpy giving me a segmentation fault? | Code context (simplify for kids): for (int i = 0; i < cmd_argc; i++) { char new_str[strlen(cmd_argv[i])]; while (cmd_argv[i][j]) { if (cmd_argv[i][j] != '\r' && cmd_argv[i][j] != '\n' && cmd_argv[i][j] != '\0') { len++; new_str[j] = cmd_argv[i][j]; } strncpy(cmd_argv[i], new_str, len); } }

Question: why is strncpy giving me a segmentation fault?


Student question: How to solve (.text+0x24): undefined reference to `main' collect2: error: ld returned 1 exit status

Question: How to solve (.text+0x24): undefined reference to `main' collect2: error: ld returned 1 exit status


Student question: why is this code never adding to client_list? | Code context (simplify for kids): if (client_fd > max_fd) { // this is a new socket max_fd = client_fd; write(client_fd, "What is your user name?\n", 24); check_and_add_user(user_list, client_fd, client_list); // add client_fd into client_list Client *new_client = (Client *)malloc(sizeof(Client)); if (new_client == NULL){ perror("ma

Question: why is this code never adding to client_list?


Student question: why is this code never adding to client_list? | Code context (simplify for kids): if (client_fd > max_fd) { // this is a new socket write(client_fd, "What is your user name?\n", 24); check_and_add_user(user_list, client_fd, client_list); // add client_fd into client_list Client *new_client = (Client *)malloc(sizeof(Client)); if (new_client == NULL){ perror("malloc"); exit(1); } n

Question: why is this code never adding to client_list?


Code context (simplify for kids): int write_inode(char *filename int index, char *name, int offset, int length) { Inode inode; FILE *fs = fopen(filenname, "r+"); strncpy(inode.name, name, MAXNAME); inode.offset = offset; inode.length = length; if (fseek(fs, index * sizeof(Inode), SEEK_SET) == -1) { perror("fseek"); return -1; }; fwr


Student question: why does it print nothing and exit when stdin gets -1? | Code context (simplify for kids): #include <stdio.h> int main() { char phone[11]; int integer; scanf("%s", phone); scanf("%d", &integer); while (integer != EOF) { if (integer == -1) { for (int i = 0; i < 10; i++) { printf("%c", phone[i]); } printf("\n"); } else if (integer > -1 && integer < 10) { printf("%c\n", phone[integer]); } el

Question: why does it print nothing and exit when stdin gets -1?


Code context (simplify for kids): Rule *curr = rules; // want to iterate to end of rules while (curr->next_rule != NULL) { curr = curr->next_rule; } // curr->next_rule == NULL curr->next_rule = new_rule; // insert new rule to end of rules


Student question: insert new rule to the end of rules | Code context (simplify for kids): Rule *curr = rules; // want to iterate to end of rules while (curr->next_rule != NULL) { curr = curr->next_rule; } // curr->next_rule == NULL curr->next_rule = new_rule; // insert new rule to end of rules

Question: insert new rule to the end of rules


Student question: insert new rule to end of rules | Code context (simplify for kids): if (rules == NULL) {rules = new_rule;} // if rules == NULL, new_rule becomes first rule else { // if rules != NULL Rule *curr = rules; // want to iterate to end of rules while (curr->next_rule != NULL) { curr = curr->next_rule; } // curr->next_rule == NULL curr->next_rule = new_rule; // insert new r

Question: insert new rule to end of rules


Code context (simplify for kids): char *ch = "S";


Student question: Declare a char variable named ch and set its value to the first letter of your own name.

Question: Declare a char variable named ch and set its value to the first letter of your own name.


Code context (simplify for kids): *delicious = "ice cream";


Student question: Set the value of delicious (which has already been declared) to "ice cream".

Question: Set the value of delicious (which has already been declared) to "ice cream".


Student question: The string sweet has been declared on the heap and has space for 20 characters. Set the value of sweet to "tiramisu" without changing its address.

Question: The string sweet has been declared on the heap and has space for 20 characters. Set the value of sweet to "tiramisu" without changing its address.


Student question: generate a detailed documentation of `typedef struct node { int value; struct node *next; } node;` with usage examples and explanations

Question: generate a detailed documentation of `typedef struct node { int value; struct node *next; } node;` with usage examples and explanations


Student question: Write a loop which traverses a linked list starting at front and prints the value of each node in the list.

Question: Write a loop which traverses a linked list starting at front and prints the value of each node in the list.


Student question: Which of these scenarios cause a memory leak?

Question: Which of these scenarios cause a memory leak?


Student question: Define a string literal called season that has the value "winter". Define a stack-allocated string called holiday that has space for 20 characters including the null terminator. Set its initial value to "Valentine's Day".

Question: Define a string literal called season that has the value "winter". Define a stack-allocated string called holiday that has space for 20 characters including the null terminator. Set its initial value to "Valentine's Day".


Student question: The difference between stack-allocated string and heap-allocated string

Question: The difference between stack-allocated string and heap-allocated string


Student question: What will be the output of the following program fragment? | Code context (simplify for kids): #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 }

Question: What will be the output of the following program fragment?


Student question: What is the line to compile it into an executable named a.out that it will print the value 5 to stdout? (You do not need to include the options to display warnings, build the symbol table for the debugger or select the C standard.) | Code context (simplify for kids): #include <stdio.h> int main() { #ifdef MACRO printf("%d\n", MACRO); #endif return 0; }

Question: What is the line to compile it into an executable named a.out that it will print the value 5 to stdout? (You do not need to include the options to display warnings, build the symbol table for the debugger or select the C standard.)


Student question: suppose we have the following line at the top of our program #define MAXNAME = 32; and then the declaration char name[MAXNAME]; in the program. What will this declaration line become after the program has passed through the C pre-processor?

Question: suppose we have the following line at the top of our program #define MAXNAME = 32; and then the declaration char name[MAXNAME]; in the program. What will this declaration line become after the program has passed through the C pre-processor?


Student question: Which of the following functions are system calls? exit() fgets() fopen() printf() read() scanf() write()

Question: Which of the following functions are system calls? exit() fgets() fopen() printf() read() scanf() write()


Student question: Which of the following functions are library calls? exit() fgets() fopen() printf() read() scanf() write()

Question: Which of the following functions are library calls? exit() fgets() fopen() printf() read() scanf() write()


Student question: What will this declaration line become after the program has passed through the C pre-processor? | Code context (simplify for kids): #define MAXNAME = 32; char name[MAXNAME];

Question: What will this declaration line become after the program has passed through the C pre-processor?


Goal: What will this declaration line become after the program has passed through the C pre-processor? | Code context (simplify for kids): #define MAXNAME = 32; char name[MAXNAME];


Goal: /* * Change the filename for the profile pic of the given user. * * Return: * - 0 on success. * - 1 if the file does not exist or cannot be opened. * - 2 if the filename is too long. */ | Code context (simplify for kids): int update_pic(User *user, const char *filename) { return -1; }


Code context (simplify for kids): User *find_user(const char *name, const User *head) { for (User *ptr = (User *)head; ptr != NULL; ptr = ptr->next) { if (strcmp(ptr->name, name) == 0) { return ptr; } } return NULL; }


Code context (simplify for kids): void printPicture(const User *user) { //if they have no profile picture we can just return since there is nothing //to print at all. if (strlen(user->profile_pic) <= 0) { return; } //continues onward because there is something that is larger than 0, //in the profile pic object. FILE *picture = fopen


Goal: remove all the posts in the linked list. | Code context (simplify for kids): void printPicture(const User *user) { //if they have no profile picture we can just return since there is nothing //to print at all. if (strlen(user->profile_pic) <= 0) { return; } //continues onward because there is something that is larger than 0, //in the profile pic object. FILE *picture = fopen


Code context (simplify for kids): void removePosts(Post *post) { //if the user has no posts then return because there is nothing to free. if (!post) { return; } //recursive function until we run out of posts to free. removePosts(post->next); //free the memory for the contents of the posts free(post->contents); free(post); }


Code context (simplify for kids): /*Purges the user from the friends list of all users in the targets list.*/ void unAddfriend(User *exiledFriend, const User *user) { if (!exiledFriend) { return; } int difference, iterator = 0; for (iterator = 0; iterator < MAX_FRIENDS && exiledFriend->friends[iterator]; iterator++) { if (exiledFrie


Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { int friendstatus = 0; User *friendo1 = find_user(name1, head); User *friendo2 = find_user(name2, head); if (friendo1 == NULL || friendo2 == NULL) { friendstatus = 4; } else if (friendo1 == friendo2) { friendstatus = 3; } int a; for


Goal: initialise two variables with the same initial value. | Code context (simplify for kids): int difference, iterator = 0;


Goal: 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 Use | Code context (simplify for kids): int make_post(const User *author, User *target, char *contents)


Student question: Select the sentence fragments that complete this sentence so that it is true. When one process forks another: the process that calls fork is called the parent and the newly-created process is the child. the code segments of the two processes are identical. the values of all the variables of the two processes are identical. the two processes have all the same variables but each process has its own

Question: Select the sentence fragments that complete this sentence so that it is true. When one process forks another: the process that calls fork is called the parent and the newly-created process is the child. the code segments of the two processes are identical. the values of all the variables of the two processes are identical. the two processes have all the same variables but each process has its own


Student question: A parent process with pid 1123 forks a child process with pid 1126. In the child process, what is the return value of fork()?

Question: A parent process with pid 1123 forks a child process with pid 1126. In the child process, what is the return value of fork()?


Student question: A parent process with pid 1123 forks a child process with pid 1126. In the parent process, what is the return value of fork()?

Question: A parent process with pid 1123 forks a child process with pid 1126. In the parent process, what is the return value of fork()?


Student question: On teach.cs, you can run man 2 wait to learn about the wait system call. Which macro is used with wait's status to check if the child process was terminated by a signal?

Question: On teach.cs, you can run man 2 wait to learn about the wait system call. Which macro is used with wait's status to check if the child process was terminated by a signal?


Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { int iterations; if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } //Get the parent id int parentPID = getpid(); iterations = strtol(argv[1], NULL, 10); for (int loopval; = 0; loo


Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { //iterations is an integer that stores //the number of iterations the program will run int loopval, iterations; if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int forked; //it


Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/wait.h> int main(int argc, char **argv) { int iterations, loopval, status; if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } iterations = strtol(argv[1], NULL, 10); for (loopval = 0; loopval < itera


Student question: Assume the following program which compiles and runs without error. What does the program print to stderr if the user presses Ctrl+C at the moment when the program is at position C? | Code context (simplify for kids): int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); // POSITION A struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); // POSITION B x += 2; // POSITION C fprintf

Question: Assume the following program which compiles and runs without error. What does the program print to stderr if the user presses Ctrl+C at the moment when the program is at position C?


Student question: Assume the following code runs without error. | Code context (simplify for kids): int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); // POSITION A struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); // POSITION B x += 2; // POSITION C fprintf

Question: Assume the following code runs without error.


Student question: Variable x has been assigned a digit between 1 and 10. Write a shell command to calculate x minus 1 and display the result to standard output.

Question: Variable x has been assigned a digit between 1 and 10. Write a shell command to calculate x minus 1 and display the result to standard output.


Student question: Variables width and height have been initialized. Calculate the area of a rectangle using width and height, and assign the resulting value to a variable named area.

Question: Variables width and height have been initialized. Calculate the area of a rectangle using width and height, and assign the resulting value to a variable named area.


Question: what is string in C?


Student question: what is the error "zsh: trace trap"

Question: what is the error "zsh: trace trap"


Student question: What is the memset syntax?

Question: What is the memset syntax?


Goal: swap num1 and num2 | Code context (simplify for kids): void swapA(int *num1, int *num2) { int *temp = num1; num1 = num2; num2 = temp; }


Code context (simplify for kids): void swapA(int *num1, int *num2) { int *temp = num1; num1 = num2; num2 = temp; }


Code context (simplify for kids): #include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }


Student question: how to get a human-readable representation of the date and time of each post in the format, "Friday Jan 27 23:01:00 2023" using time and ctime functions?

Question: how to get a human-readable representation of the date and time of each post in the format, "Friday Jan 27 23:01:00 2023" using time and ctime functions?


Student question: generate a detailed documentation of `time` with usage examples and explanations

Question: generate a detailed documentation of `time` with usage examples and explanations


Student question: Why is time and ctime not giving me the current time but an arbitrary time?

Question: Why is time and ctime not giving me the current time but an arbitrary time?


Student question: generate a detailed documentation of `time` with usage examples and explanations

Question: generate a detailed documentation of `time` with usage examples and explanations


Student question: how do I use time to get the current time? Not the time since epoch?

Question: how do I use time to get the current time? Not the time since epoch?


Question: how to use stat?


Student question: how do I append to a list in C?

Question: how do I append to a list in C?


Student question: what does this do? | Code context (simplify for kids): char *result[2];

Question: what does this do?


Student question: can you show me a visual representation? | Code context (simplify for kids): char *result[2];

Question: can you show me a visual representation?


Code context (simplify for kids): struct pixel **pixels = read_pixel_array(image, pixel_array_offset, width, height);


Student question: how to allocate space on stack for many values?

Question: how to allocate space on stack for many values?


Student question: an array of pointers to structs

Question: an array of pointers to structs


Student question: how to traverse a linked list to find a specific struct

Question: how to traverse a linked list to find a specific struct


Question: explain fork()


Code context (simplify for kids): 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 = for


Student question: when would we ever get to the else branch | Code context (simplify for kids): 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 = for

Question: when would we ever get to the else branch


Student question: STDIN_FILENO what is that

Question: STDIN_FILENO what is that


Student question: STDIN_FILENO what is that

Question: STDIN_FILENO what is that


Question: what is excel


Question: excel() funtion


Question: execl() what is it?


Question: how does dup2 work


Student question: what are argyments to pipe

Question: what are argyments to pipe


Student question: how to check if a file in a directory exists?

Question: how to check if a file in a directory exists?


Student question: how are makefiles evaluated

Question: how are makefiles evaluated


Student question: can you use printf on an array of char pointers?

Question: can you use printf on an array of char pointers?


Question: how does execvp work


Student question: how to use stat to get the last modified time of a file

Question: how to use stat to get the last modified time of a file


Student question: what is struct timespec;

Question: what is struct timespec;


Student question: how do I use the tv_sec member of stat.st_mtim?

Question: how do I use the tv_sec member of stat.st_mtim?


Student question: what is this code chunk doing | Code context (simplify for kids): // 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); }

Question: what is this code chunk doing


Student question: explain asprintf and snprintf and their differences

Question: explain asprintf and snprintf and their differences


Student question: what are the arguments to asprintf()

Question: what are the arguments to asprintf()


Student question: I want to dynamically alocate a string that keeps appending charcters to the buffer with asprintf()

Question: I want to dynamically alocate a string that keeps appending charcters to the buffer with asprintf()


Student question: is there a way to use asprintf and continually append to the same character buffer?

Question: is there a way to use asprintf and continually append to the same character buffer?


Code context (simplify for kids): 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");


Code context (simplify for kids): 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 && proc


Code context (simplify for kids): 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");


Code context (simplify for kids): 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 d


Code context (simplify for kids): int i; while((scanf(%d), i) != EOF){ }


Code context (simplify for kids): int i; while((scanf(%d), i) != EOF){ printf(i) }


Code context (simplify for kids): NumberOfElements = sizeof(arr)/sizeof(arr[0]);


Goal: print user information, fix set fault | Code context (simplify for kids): 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


Goal: segmentation fault | Code context (simplify for kids): 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


Student question: recursively run the function | Code context (simplify for kids): 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_d

Question: recursively run the function


Code context (simplify for kids): 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


Student question: when using asprintf multiple times with the same buffer is it neccessary to free memory multiple times or just once at the end

Question: when using asprintf multiple times with the same buffer is it neccessary to free memory multiple times or just once at the end


Goal: return int ** | Code context (simplify for kids): 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; f


Student question: how to declare a pointer to point to dynamically allocated arrays

Question: how to declare a pointer to point to dynamically allocated arrays


Student question: how to access elements from a pointer that points to an array

Question: how to access elements from a pointer that points to an array


Student question: how to store something on the heap

Question: how to store something on the heap


Student question: how to store an array on the heap

Question: how to store an array on the heap


Goal: why is s being changed? | Code context (simplify for kids): 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)


Goal: is s being changed? | Code context (simplify for kids): 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; f


Goal: s does not change | Code context (simplify for kids): 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; f


Student question: does s change? | Code context (simplify for kids): 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; f

Question: does s change?


Student question: what are the values of s in the beginning? | Code context (simplify for kids): 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; f

Question: what are the values of s in the beginning?


Student question: should s change at the end of the code? | Code context (simplify for kids): 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; f

Question: should s change at the end of the code?


Student question: where is s, array1, and array2 stored? | Code context (simplify for kids): 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; f

Question: where is s, array1, and array2 stored?


Task: 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.


Code context (simplify for kids): 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; f


Student question: How do you declare an array of chars?

Question: How do you declare an array of chars?


Student question: how do you declare an array of chars of unknown size?

Question: how do you declare an array of chars of unknown size?


Student question: How to copy a string to an empty string

Question: How to copy a string to an empty string


Student question: How to declare empty string as destination string to for strcpy?

Question: How to declare empty string as destination string to for strcpy?


Student question: How to allocate space for 5 `struct pixel *` values

Question: How to allocate space for 5 `struct pixel *` values


Student question: How to store two dimensional array on heap

Question: How to store two dimensional array on heap


Student question: What is code to store two dimensional array on heap

Question: What is code to store two dimensional array on heap


Student question: How to declare a pointer to the current date?

Question: How to declare a pointer to the current date?


Student question: How to get the current date?

Question: How to get the current date?


Student question: #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?

Question: #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?


Student question: What will the declaration on line 2 become after the program has passed through the C pre-processor? | Code context (simplify for kids): #define MAXNAME = 32; char name[MAXNAME];

Question: What will the declaration on line 2 become after the program has passed through the C pre-processor?


Student question: What is the output? | Code context (simplify for kids): #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 }

Question: What is the output?


Student question: What is the output? | Code context (simplify for kids): #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 }

Question: What is the output?


Student question: how to declare strings

Question: how to declare strings


Question: how to use fread?


Student question: using SEEK_CUR of fread

Question: using SEEK_CUR of fread


Student question: How can I use the line of a file as the arguments to my c program in a shell script

Question: How can I use the line of a file as the arguments to my c program in a shell script


Goal: copy the contents of second_one into my_string | Code context (simplify for kids): #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; }


Student question: if the file exists set target_time to the st_mtime which is a struct | Code context (simplify for kids): 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; }

Question: if the file exists set target_time to the st_mtime which is a struct


Task: how to use struct timespec st_mtim; to get the most recent file between two files


Question: What is Fseek


Question: how to open a file


Student question: how to check if opening file caused error

Question: how to check if opening file caused error


Student question: read contents in a file

Question: read contents in a file


Student question: is there a segmentation fault here | Code context (simplify for kids): FILE *picture = fopen(user->profile_pic, "r");

Question: is there a segmentation fault here


Goal: Supposed to read the contents in the file picture and print it | Code context (simplify for kids): 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); }


Student question: ==41828== Syscall param openat(filename) points to uninitialised byte(s) what does this mean

Question: ==41828== Syscall param openat(filename) points to uninitialised byte(s) what does this mean


Student question: Fix this error Syscall param openat(filename) points to uninitialised byte(s) | Code context (simplify for kids): 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); } }

Question: Fix this error Syscall param openat(filename) points to uninitialised byte(s)


Student question: Does it matter if I read the file in chunks of 32 bits | Code context (simplify for kids): 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); } }

Question: Does it matter if I read the file in chunks of 32 bits


Student question: Should I change the fgets to 1 bit | Code context (simplify for kids): 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); } }

Question: Should I change the fgets to 1 bit


Student question: If I do not know the number of characters in a file, but need to use fgets. What should the second parameter be

Question: If I do not know the number of characters in a file, but need to use fgets. What should the second parameter be


Student question: I dont see why I am getting a Invalid read of size 8 error on line 8 | Code context (simplify for kids): 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; }

Question: I dont see why I am getting a Invalid read of size 8 error on line 8


Goal: I am supposed to put new_post in the beginning of the target->first_post and I need help with malloc | Code context (simplify for kids): new_post->next = target->first_post; target->first_post = new_post;


Goal: This is causing the new post to be added countless times | Code context (simplify for kids): // 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; }


Goal: I want it to add the new post at the beginning of the target->first_post | Code context (simplify for kids): // 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; }


Code context (simplify for kids): // 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); str


Goal: 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. | Code context (simplify for kids): // 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); str


Student question: how do I print a time_t data

Question: how do I print a time_t data


Question: print from a time_t *


Code context (simplify for kids): /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"); } }


Student question: Why am I getting a curr may not be initialized error | Code context (simplify for kids): // 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("

Question: Why am I getting a curr may not be initialized error


Question: How do I use calloc


Student question: Can you spot the conditional move depends on uninitialized error here | Code context (simplify for kids): 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("------------

Question: Can you spot the conditional move depends on uninitialized error here


Student question: Are there any issues | Code context (simplify for kids): 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");

Question: Are there any issues


Code context (simplify for kids): // Go through all the user's posts and free memory allocated for it Post *posts = NULL; Post *prev_post = to_delete->first_post; while (prev_post != NULL){ posts = prev_post; free(posts->contents); free(posts->date); prev_post = prev_post->next; free(posts); } // Free user itself's memory free(to_de


Goal: I have a never terminating loop here | Code context (simplify for kids): // Go through all the user's posts and free memory allocated for it Post *posts = NULL; Post *prev_post = to_delete->first_post; while (prev_post != NULL){ posts = prev_post; free(posts->contents); free(posts->date); prev_post = prev_post->next; free(posts); } // Free user itself's memory free(to_de


Goal: It is supposed to act like strncopy | Code context (simplify for kids): // Allocate Null space to all the characters in dest memset(dest, '\0', capacity); // Go through the src string and copy characters int i = 0; for (i; i < (capacity-1); i++){ if (src[i] != '\0'){ dest[i] = src[i]; } } return dest;


Student question: The code is not outputting Welcome.\r\n even though its a new user | Code context (simplify for kids): // New user if (found == 0){ // Welcome the client char *message = "Welcome.\r\n"; write(new_user->fd, message, strlen(message)); // Note down the name strncpy(new_user->name, buf, strlen(new_user->name)); new_user->name[31] = '\0'; } }

Question: The code is not outputting Welcome.\r\n even though its a new user


Student question: how do i ignore a line of input using scanf

Question: how do i ignore a line of input using scanf


Student question: what is the complexity of this code | Code context (simplify for kids): AVL_Node* search(AVL_Node* node, int key) { //*** if (node == NULL) { return NULL; } if (key == node->key) { return node; } if (key < node->key) { return search(node->left, key); } return search(node->right, key); }

Question: what is the complexity of this code


Student question: pseudocode for avl insert?

Question: pseudocode for avl insert?


Student question: what are processes in C

Question: what are processes in C


Question: what does dup2 do


Student question: what is a file descriptor

Question: what is a file descriptor


Student question: lldb is telling me line 3 is causing a segfault. how do i fix this | Code context (simplify for kids): target = malloc(sizeof(char) * (strchr(makefile_line, ':') - makefile_line)); strncpy(target, makefile_line, strchr(makefile_line, ':') - makefile_line - 1); target[strchr(makefile_line, ':') - makefile_line - 1] = '\0';

Question: lldb is telling me line 3 is causing a segfault. how do i fix this


Student question: what algorithm is this | Code context (simplify for kids): Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeEdges, min->fromVertex, min->toVertex, min->weight); } Ad

Question: what algorithm is this


Student question: how do you implement dijkstra's algorithm

Question: how do you implement dijkstra's algorithm


Student question: what algorithm is this | Code context (simplify for kids): Records *records = initRecords(graph, startVertex); for (int i = 0; i < graph->numVertices; i++) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeEdges, min->fromVertex, min->toVertex, min->

Question: what algorithm is this


Student question: consider these two functions | Code context (simplify for kids): Records *initRecords(Graph *graph, int startVertex) { Records *records = malloc(sizeof(Records)); records->numVertices = graph->numVertices; records->heap = initHeap(graph, startVertex); records->finished = malloc(sizeof(bool) * graph->numVertices); records->predecessors = malloc(sizeof(int) * graph

Question: consider these two functions


Student question: what is getPaths returning here | Code context (simplify for kids): Edge *getShortestPaths(Graph *graph, int startVertex) { Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeE

Question: what is getPaths returning here


Student question: what algorithm(s) are being displayed here | Code context (simplify for kids): Edge *getShortestPaths(Graph *graph, int startVertex) { Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeE

Question: what algorithm(s) are being displayed here


Code context (simplify for kids): Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeEdges, min->fromVertex, min->toVertex, min->weight); } Ad


Student question: what algorithm does this use | Code context (simplify for kids): Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { HeapNode *min = extractMin(records->heap); records->finished[min->edge.toVertex] = true; if (min->edge.fromVertex != min->edge.toVertex) { addTreeEdge(records, records->numTreeEdges, min->edge.fromVertex, min->edge

Question: what algorithm does this use


Student question: what algorithm does this use | Code context (simplify for kids): Records *records = initRecords(graph, startVertex); while (!isEmpty(records->head)) { HeapNode min = extractMin(records->heap); records->finished[min.id] = true; addTreeEdge(records, records->numTreeEdges, min.id, records->predecessors[min.id], min.priority); AdjList *neighbors = graph->vertices[min

Question: what algorithm does this use


Student question: what algorithm does this use | Code context (simplify for kids): Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Heapnode min = extractMin(records->heap); records->finished[min.id] = true; addTreeEdge(records, records->numTreeEdges, min.id, records->predecessors[min.id], min.priority); AdjList *neighbors = graph->vertices[min

Question: what algorithm does this use


Student question: what algorithm is being implemented here | Code context (simplify for kids): Records *asdfg123 = initRecords(graph, startVertex); while (!isEmpty(asdfg123->heap)) { HeapNode min = extractMin(asdfg123->heap); asdfg123->finished[min.id] = true; addTreeEdge(asdfg123, asdfg123->numTreeEdges, min.id, asdfg123->predecessors[min.id], min.priority); AdjList *neighbours = graph->vert

Question: what algorithm is being implemented here


Student question: what algorithm is being used here | Code context (simplify for kids): Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { HeapNode min = extractMin(records->heap); records->finished[min.id] = true; addTreeEdge(records, records->numTreeEdges, min.id, records->predecessors[min.id], min.priority); AdjList *neighbors = graph->vertices[min

Question: what algorithm is being used here


Student question: which algorithm is (1) using and which algorithm is (2) using? | Code context (simplify for kids): (1) Records *asdfg123 = initRecords(graph, startVertex); while (!isEmpty(asdfg123->heap)) { HeapNode min = extractMin(asdfg123->heap); asdfg123->finished[min.id] = true; addTreeEdge(asdfg123, asdfg123->numTreeEdges, min.id, asdfg123->predecessors[min.id], min.priority); AdjList *neighbours = graph->

Question: which algorithm is (1) using and which algorithm is (2) using?


Student question: what algorithm is this | Code context (simplify for kids): Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { HeapNode min = extractMin(records->heap); records->finished[min.id] = true; addTreeEdge(records, records->numTreeEdges, min.id, records->predecessors[min.id], min.priority); AdjList *neighbors = graph->vertices[min

Question: what algorithm is this


Student question: what algorithm is this | Code context (simplify for kids): Records *asdfg123 = initRecords(graph, startVertex); while (!isEmpty(asdfg123->heap)) { HeapNode min = extractMin(asdfg123->heap); asdfg123->finished[min.id] = true; addTreeEdge(asdfg123, asdfg123->numTreeEdges, min.id, asdfg123->predecessors[min.id], min.priority); AdjList *neighbours = graph->vert

Question: what algorithm is this


Code context (simplify for kids): import web_resource as web_r import os import threading import youtube_api import util import os import google.auth import datetime from googleapiclient.discovery import build from youtube_transcript_api import YouTubeTranscriptApi class YouTubeAPI(web_r.web_results) : def result_from_youtube(self,


Code context (simplify for kids): int main(int argc, char **argv) { if (argc == 2){ int c; enum { START, SAW_NL, SAW_TWO_NL } state = START; while ((c = getchar()) != EOF) { if (c == 10){ if (state == START){ putchar(c); state = SAW_NL; }else if (state == SAW_NL){ putchar(c); state = SAW_TWO_NL; } }else{ state = START; putchar(c); }


Goal: 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 | Code context (simplify for kids): #include <stdio.h> int main(){ char phone[11]; int d; int scanf_return; scanf("%s", phone); // getting first input int err = 0; // variable for return value of program do{ scanf_return = scanf("%d", &d); if (d == -1){ printf("%s\n", phone); } else if (d<-1 || d>9){ printf("ERROR\n"); err = 1; } else


Goal: Your task is to write a C program called phone_loop.c. This program will again read from standard input using scanf and take no command-line arguments. Similar to phone.c, this program reads a 10-character string as the first input value but then it repeatedly reads integers until standard input is closed. (Hint: Use a while loop that checks the return value of scanf to accomplish this. Check the  | Code context (simplify for kids): #include <stdio.h> int main(){ char phone[11]; int d; int scanf_return; scanf("%s", phone); // getting first input int err = 0; // variable for return value of program do{ scanf_return = scanf("%d", &d); if (d == -1){ printf("%s\n", phone); } else if (d<-1 || d>9){ printf("ERROR\n"); err = 1; } else


Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *, char *); int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1;


Student question: why am I getting a segmentation fault | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *, char *); int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1;

Question: why am I getting a segmentation fault


Goal: take input from ls -l terminal command as well as one or two command line arguments and return the number of files greater in size | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> #include <string.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(const char *input_permissions, const char *required_permissions) { for (int i = 0; i < 9; i++) { if (required_permissions[i] == '-')


Student question: How do you printf a date of time_t

Question: How do you printf a date of time_t


Student question: The compiler is saying that this is invalid and that a long type is necessary | Code context (simplify for kids): new_post->date = time(NULL);

Question: The compiler is saying that this is invalid and that a long type is necessary


Student question: new_post->date is of type time_t but this line of code is being flagged as an error and invalid | Code context (simplify for kids): new_post->date = time(NULL);

Question: new_post->date is of type time_t but this line of code is being flagged as an error and invalid


Student question: What are the values of an initialized array

Question: What are the values of an initialized array


Code context (simplify for kids): int *arr[2];


Code context (simplify for kids): String.join()


Code context (simplify for kids): String.concat()


Student question: How to make string copy

Question: How to make string copy


Code context (simplify for kids): strtol


Question: what is struct


Student question: waht is stored in struct

Question: waht is stored in struct


Student question: what is the syntax for copying a string

Question: what is the syntax for copying a string


Goal: truncate input at n | Code context (simplify for kids): #include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters


Goal: truncate string at n | Code context (simplify for kids): #include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters


Goal: truncate s at n | Code context (simplify for kids): #include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters


Goal: replace first 0 in friends of User name1 with User name2 and replace first 0 in friends of User name2 with User name1 | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { User *curr = head; User *user1 = NULL; User *user2 = NULL; //traverses through list, assigns curr to user 1 and user2 if(strcmp(name1, name2)==0){ return 3; } else{ while(curr != NULL){ if(strcmp(curr ->name, name1)==0 ){ user1 = c


Goal: replace first 0 in friend array of User name1 with User name2 and replace the first 0 in friend array of User name 2 with User name1 | Code context (simplify for kids): int make_friends(const char *name1, const char *name2, User *head) { User *curr = head; User *user1 = NULL; User *user2 = NULL; //traverses through list, assigns curr to user 1 and user2 if(strcmp(name1, name2)==0){ return 3; } else{ while(curr != NULL){ if(strcmp(curr ->name, name1)==0 ){ user1 = c


Goal: make all elements in new_user ->friends a 0 | Code context (simplify for kids): memset(new_user->friends, 0, MAX_FRIENDS * sizeof(new_user -> friends[0]));


Student question: how to cast const User struct to User struct

Question: how to cast const User struct to User struct


Student question: when do you use malloc

Question: when do you use malloc


Student question: when should you use malloc for a struct

Question: when should you use malloc for a struct


Code context (simplify for kids): #include <stdio.h> int main(){ char phone_num[11]; scanf("%s", phone_num); int a, contains_error = 0; while(1){ scanf("%d", &a); if(a == -1){ printf("%s\n", phone_num); }else if(a >= 0 && a <= 9){ printf("%c\n", phone_num[a]); }else{ printf("ERROR\n"); contains_error = 1; } } if(contains_error){ ret


Student question: how do i detect the end of stdin

Question: how do i detect the end of stdin


Student question: how to i detect the end of stdin IN C CODE

Question: how to i detect the end of stdin IN C CODE


Student question: how to detect the end of stdin using scanf in C code

Question: how to detect the end of stdin using scanf in C code


Student question: How to separate a string by \n?

Question: How to separate a string by \n?


Goal: How can I assign arr[0][i] to s[i] | Code context (simplify for kids): int **split_array(const int *s, int length) { int **arr = (int **)malloc(sizeof(int)*length); arr[0] = (int *) malloc(sizeof(int)* length/2); arr[1] = (int *) malloc(sizeof(int)* length/2); for(int i = 0; i < length; i++){ if(i%2 == 0){ arr[0][i] = s[i]; } if(i%2 == 1){ arr[1][i] = s[i]; } } return


Goal: how can I assign each arr[i] for each part of a long type variable. | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(*strs,NULL,10); } return arr; }


Goal: how can I assign each arr[i] from the strtol | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs[i],NULL,10); } return arr; }


Goal: How can I assign i[0] | Code context (simplify for kids): int *build_array(char **strs, int size) { long i = strtol(strs,NULL,10); i[0] = 0; }


Goal: How can I assign i[0] | Code context (simplify for kids): int *build_array(char **strs, int size) { long *arr = malloc(sizeof(long)*size); arr = strtol(strs,NULL,10); arr[0] = 0; }


Goal: How can I assign i[0] | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); arr = strtol(strs,NULL,10); arr[0] = 0; }


Goal: How can I assign i[0] | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); arr[0] = strtol(strs[0],NULL,10); }


Goal: How can I assign i[0] | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs[i],NULL,10); } return arr; }


Goal: How can I assign arr[0] | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs[i],NULL,10); } return arr; }


Goal: How can I assign arr[0] | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs,NULL,10); } return arr; }


Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs[i],NULL,10); } return arr; }


Goal: How to compare required[i] with "-" | Code context (simplify for kids): int check_permissions(char *file[9], char *required[9]) { for (int i = 0; i < 9; i++) { if (required[i] != "-") { if (file[i] != required[i]) { return 1; } } } return 0; }


Goal: how can I get value of index i in the required | Code context (simplify for kids): int check_permissions(char *file, char *required) { for (int i = 0; i < 9; i++) { if (required[i] != "-") { if (file[i] != required[i]) { return 1; } } } return 0; }


Student question: how can i extract permissions value from ls -l

Question: how can i extract permissions value from ls -l


Student question: how can I assign permissions form ls -l to a variable

Question: how can I assign permissions form ls -l to a variable


Student question: Can access file's index which is the output from ls-l by file[i][4] | Code context (simplify for kids): int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } // TODO: Process command line arguments. char *file; scanf("%s", file) // TODO: Call check_permissions as part of your solution to count the files to // compute

Question: Can access file's index which is the output from ls-l by file[i][4]


Student question: Can assign the output from ls-l to a string?

Question: Can assign the output from ls-l to a string?


Student question: How to user scanf for the output of ls-l

Question: How to user scanf for the output of ls-l


Student question: The type of output of ls-l

Question: The type of output of ls-l


Student question: How to know how many command-line arguments are being given?

Question: How to know how many command-line arguments are being given?


Student question: how can I use `argc` ?

Question: how can I use `argc` ?


Student question: How to modify a string literal?

Question: How to modify a string literal?


Student question: How to reassign a string literal?

Question: How to reassign a string literal?


Student question: Is there any issues? | Code context (simplify for kids): int check_friends(User *user1, User *user2){ for(int i = 0; i < 10; i++){ if(user1->friends[i]){ if(user1->friends[i]->name == user2->name){ return 0; } } } return 1; }

Question: Is there any issues?


Goal: How to fix segmentation fault? | Code context (simplify for kids): char str[1000]; FILE *fptr; fptr = fopen(user->profile_pic,"r"); if(fptr != NULL){ if(fgets(str, 1000, fptr) != NULL){ printf("%s",str); } }


Goal: How to fix segmentation fault? | Code context (simplify for kids): char str[1000]; FILE *fptr; fptr = fopen(user->profile_pic,"r"); if(fptr != NULL){ if(fgets(str, 1000, fptr) != NULL){ printf("%s",str); } } fclose(fptr);


Code context (simplify for kids): char str[1000]; FILE *fptr; fptr = fopen(user->profile_pic,"r"); if(fptr != NULL){ if(fgets(str, 1000, fptr) != NULL){ printf("%s",str); fclose(fptr); } }


Student question: how can i check how many digits an integer has in c

Question: how can i check how many digits an integer has in c


Student question: what kind of info does ls -l give

Question: what kind of info does ls -l give


Student question: why am i failing the sanity check

Question: why am i failing the sanity check


Goal: reasons for sanity check fail | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. //int check_permissions(char *, char *); int check_permissions(char *given_perms, char *req_perms){ for(int i = 0; i < 9; i++){ if (req_perms[i]!='-'){ if(given_perms[i]!=req_


Goal: read from a file | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. //int check_permissions(char *, char *); int check_permissions(char *given_perms, char *req_perms){ for(int i = 0; i < 9; i++){ if (req_perms[i]!='-'){ if(given_perms[i]!=req_


Student question: how can i cast a (const User *) to a (User *)

Question: how can i cast a (const User *) to a (User *)


Question: what is a const


Student question: how do linked lists work in c

Question: how do linked lists work in c


Student question: how can i print a text file to standard output

Question: how can i print a text file to standard output


Goal: each child process needs to have a different id | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int child_num = 0; for (int i = 0; i < iterations; i++) { int n = fork(); if (n == 0


Student question: how can i check if a struct is null

Question: how can i check if a struct is null


Task: create a linkedlist structure that keeps track of names


Task: check that a line starts with a tab


Student question: change this to strncpy | Code context (simplify for kids): strcpy(copied_action_line, action_line);

Question: change this to strncpy


Student question: difference between string literal and string | Code context (simplify for kids): char *s = "hi"; char s[] = "hi";

Question: difference between string literal and string


Student question: what is y | Code context (simplify for kids): char *s = "hi"; char x = "hello" char **y = &x;

Question: what is y


Student question: what is friends | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User;

Question: what is friends


Student question: what is the initial value of a string

Question: what is the initial value of a string


Student question: what is null character

Question: what is null character


Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User;


Student question: what is the initial value of firends | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User;

Question: what is the initial value of firends


Code context (simplify for kids): int i, j = 0;


Code context (simplify for kids): int i, j = 0, 0;


Student question: What is the pointer that point to NULL

Question: What is the pointer that point to NULL


Student question: is p NULL | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; User u; u = NULL; User *p = &u;

Question: is p NULL


Student question: how to figure out a pointer is pointing to NULL?

Question: how to figure out a pointer is pointing to NULL?


Code context (simplify for kids): char s[10]; s = NULL;


Student question: what does the function time() do?

Question: what does the function time() do?


Student question: what does the function ctime() do?

Question: what does the function ctime() do?


Student question: what is the arguments of function time()

Question: what is the arguments of function time()


Student question: what will User->next->name be? | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User;

Question: what will User->next->name be?


Student question: what is the argument of free()

Question: what is the argument of free()


Question: Is string a pointer?


Student question: If the first part of and is False, will it check the second part of and?

Question: If the first part of and is False, will it check the second part of and?


Question: what is and symbol


Student question: Difference between & and &&

Question: Difference between & and &&


Student question: How to remove an element in an array

Question: How to remove an element in an array


Student question: what will i[2] be? | Code context (simplify for kids): int i[2]; i[0] = 1; i[1] = 2;

Question: what will i[2] be?


Student question: What is the argument of ctime()

Question: What is the argument of ctime()


Student question: can I set u.profile_pic to NULL | Code context (simplify for kids): typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; User u; u.profile_pic = NULL;

Question: can I set u.profile_pic to NULL


Student question: what is the initial value of profile_pic? | Code context (simplify for kids): char profile_pic[32]

Question: what is the initial value of profile_pic?


Student question: what is the value of profile_pic? | Code context (simplify for kids): char profile_pic[32] profile_pic[0] = '\0'

Question: what is the value of profile_pic?


Student question: Can I set a variable contains a struct to NULL?

Question: Can I set a variable contains a struct to NULL?


Student question: what is the value of empty_friends? | Code context (simplify for kids): #define MAX_NAME 32 // Max username and profile_pic filename lengths #define MAX_FRIENDS 10 // Max number of friends a user can have typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MA

Question: what is the value of empty_friends?


Student question: how to assign to expression with array

Question: how to assign to expression with array


Student question: When I create an object of a struct, will the values in the struct be created automatically?

Question: When I create an object of a struct, will the values in the struct be created automatically?


Student question: how to assign an array to the attributes of a struct

Question: how to assign an array to the attributes of a struct


Student question: how to assign variable with array

Question: how to assign variable with array


Student question: what is the difference between ptr = &value and *ptr = value?

Question: what is the difference between ptr = &value and *ptr = value?


Student question: if I want to assign value to a string literal which is a variable of a struct, what should I do?

Question: if I want to assign value to a string literal which is a variable of a struct, what should I do?


Student question: Does the for-loop counter disappear after the loop stoped

Question: Does the for-loop counter disappear after the loop stoped


Student question: show the standard outpuy | Code context (simplify for kids): for (int i=0; i < 5; i++){ printf("%d\n", i); } printf("%d\n", i+1);

Question: show the standard outpuy


Student question: what does dup2 function do

Question: what does dup2 function do


Student question: do you know current CSC209 A3?

Question: do you know current CSC209 A3?


Student question: How to read lines of a makefile?

Question: How to read lines of a makefile?


Student question: What does this function return if line is empty? | Code context (simplify for kids): int is_comment_or_empty(const char *line) { for (int i = 0; i < strlen(line); i++) { if (line[i] == '#') { return 1; } if (line[i] != '\t' && line[i] != ' ') { return 0; } } return 1; }

Question: What does this function return if line is empty?


Student question: How to separate a string by " "?

Question: How to separate a string by " "?


Student question: should we always allocate spaces on the heap for structs if we want to get access to it after function returns?

Question: should we always allocate spaces on the heap for structs if we want to get access to it after function returns?


Student question: what will this file print? | Code context (simplify for kids): #include <stdio.h> #include <string.h> int main() { char str[80] = "This is - www.tutorialspoint.com - website"; const char s[2] = "-"; char *token; token = strtok(str, s); while (token != NULL) { printf(" %s\n", token); token = strtok(NULL, s); } return (0); }

Question: what will this file print?


Student question: What will fgets() function get if the line is empty

Question: What will fgets() function get if the line is empty


Student question: How to strip a string after using fgets()?

Question: How to strip a string after using fgets()?


Student question: what will it print? | Code context (simplify for kids): #include <stdio.h> #include <string.h> int main() { char str[100] = "Hello, world!\n"; char *token; token = strtok(str, "\n"); // split the string at "\n" strcat(token, ""); // concatenate the tokens to get the final string printf("%s", token); // print the string without "\n" return 0; }

Question: what will it print?


Question: what will it print?


Student question: what will it print? | Code context (simplify for kids): #include <stdio.h> #include <string.h> int main() { char str[100] = "Hello, world!\n"; char *token; str = strtok(str, "\n"); // split the string at "\n" strcat(str, ""); // concatenate the tokens to get the final string printf("%s", str); // print the string without "\n" return 0; }

Question: what will it print?


Student question: what will it print? | Code context (simplify for kids): #include <stdio.h> #include <string.h> int main() { char str[100] = "Hello, world!\n"; char *token; str = strtok(str, "\n"); // split the string at "\n" // strcat(str, ""); // concatenate the tokens to get the final string printf("%s", str); // print the string without "\n" return 0; }

Question: what will it print?


Student question: is line 7 correct? | Code context (simplify for kids): #include <stdio.h> #include <string.h> int main() { char str[100] = "Hello, world!\n"; str = strtok(str, "\n"); // split the string at "\n" strcat(str, ""); // concatenate the tokens to get the final string printf("%s", str); // print the string without "\n" return 0; }

Question: is line 7 correct?


Student question: is line 7 correct? | Code context (simplify for kids): #include <stdio.h> #include <string.h> int main() { char *str = "Hello, world!\n"; str = strtok(str, "\n"); // split the string at "\n" strcat(str, ""); // concatenate the tokens to get the final string printf("%s", str); // print the string without "\n" return 0; }

Question: is line 7 correct?


Student question: is line 7 correct? | Code context (simplify for kids): #include <stdio.h> #include <string.h> int main() { char str[100] = "Hello, world!\n"; char *token; token = strtok(str, "\n"); // split the string at "\n" strcpy(str, token); printf("%s", str); // print the string without "\n" return 0; }

Question: is line 7 correct?


Student question: is line 7 correct? | Code context (simplify for kids): #include <stdio.h> #include <string.h> int main() { char str[100] = "Hello, world!\n"; char *token; token = strtok(str, "\n"); // split the string at "\n" printf("%s", token); // print the string without "\n" return 0; }

Question: is line 7 correct?


Student question: what will str be after line 8? | Code context (simplify for kids): #include <stdio.h> #include <string.h> int main() { char str[100] = "Hello, world!\n"; char *token; token = strtok(str, "\n"); // split the string at "\n" strcpy(str, token); printf("%s", token); // print the string without "\n" return 0; }

Question: what will str be after line 8?


Student question: How to read a file again?

Question: How to read a file again?


Student question: how to read a file twice in a function

Question: how to read a file twice in a function


Student question: what does fgets() return?

Question: what does fgets() return?


Student question: how to report error if error occurred during malloc?

Question: how to report error if error occurred during malloc?


Student question: if I split a string "\t hello world" by strtok, what will the result be?

Question: if I split a string "\t hello world" by strtok, what will the result be?


Student question: If I use strtok() to a string contains '\t' by delimiter " ", and then I keep printing strtok(NULL, space), will '\t' be printed out?

Question: If I use strtok() to a string contains '\t' by delimiter " ", and then I keep printing strtok(NULL, space), will '\t' be printed out?


Student question: How to debug using terminal

Question: How to debug using terminal


Question: how to copy a string?


Question: what does \r mean?


Student question: how to use strtok to strip \n and \r

Question: how to use strtok to strip \n and \r


Question: explain strncpy()


Student question: how to strip '\n' of a string by using strtok

Question: how to strip '\n' of a string by using strtok


Student question: 1 is equal to true or false

Question: 1 is equal to true or false


Student question: split line "\tgcc -Wall -g -std=gnu99 -o main linked_list.o main.o" by " " and forms an array of strings | Code context (simplify for kids): char **helper_build_action(char *line){ char **result = malloc(MAXLINE * sizeof(char)); if (result == NULL){ perror("Error occurred during malloc"); exit(1); } char *tk = strtok(line, " "); int i = 0; tk = strtok(NULL, " "); while(tk != NULL){ result[i] = tk; i += 1; tk = strtok(NULL, " "); } result

Question: split line "\tgcc -Wall -g -std=gnu99 -o main linked_list.o main.o" by " " and forms an array of strings


Student question: input: line = "\tgcc -Wall -g -std=gnu99 -o main linked_list.o main.o" desired output = ["gcc", "-Wall", "-g", "-std=gnu99", "-o", "main", "linked_list.o", "main.o", NULL] | Code context (simplify for kids): char **helper_build_action(char *line){ char **result = malloc(MAXLINE * sizeof(char)); if (result == NULL){ perror("Error occurred during malloc"); exit(1); } char *tk = strtok(line, "\t"); int i = 0; tk = strtok(NULL, "\t"); while(tk != NULL){ result[i] = strdup(tk); i += 1; tk = strtok(NULL, " ")

Question: input: line = "\tgcc -Wall -g -std=gnu99 -o main linked_list.o main.o" desired output = ["gcc", "-Wall", "-g", "-std=gnu99", "-o", "main", "linked_list.o", "main.o", NULL]


Student question: Intended Behavior: input: line = "\tgcc -Wall -g -std=gnu99 -o main linked_list.o main.o" result = ["gcc", "-Wall", "-g", "-std=gnu99", "-o", "main", "linked_list.o", "main.o", NULL] | Code context (simplify for kids): char **helper_build_action(char *line){ char **result = malloc(MAXLINE * sizeof(char)); if (result == NULL){ perror("Error occurred during malloc"); exit(1); } char *tk = strtok(line, "\t"); int i = 0; tk = strtok(NULL, "\t"); while(tk != NULL){ result[i] = strdup(tk); i += 1; tk = strtok(NULL, " ")

Question: Intended Behavior: input: line = "\tgcc -Wall -g -std=gnu99 -o main linked_list.o main.o" result = ["gcc", "-Wall", "-g", "-std=gnu99", "-o", "main", "linked_list.o", "main.o", NULL]


Question: what does execvp do


Question: how to call stat?


Student question: what is the difference between perror and fprintf

Question: what is the difference between perror and fprintf


Student question: How to use access to determine file existence.

Question: How to use access to determine file existence.


Student question: how to initialize a variable taking true/false value

Question: how to initialize a variable taking true/false value


Student question: what is st_mtim in struct stat?

Question: what is st_mtim in struct stat?


Question: Explain WIFEXIT


Student question: Should child process always use exit(0) at the end?

Question: Should child process always use exit(0) at the end?


Question: is pid_t int?


Question: explain WIFEXITED


Question: explain WEXITSTATUS


Question: explain WEXITSTATUS


Student question: How to generate a random int between 0 to 99

Question: How to generate a random int between 0 to 99


Student question: what does it mean if a loop header is for (;;)

Question: what does it mean if a loop header is for (;;)


Task: Generate a random integer from 0 to 100


Student question: if I add a signal handler to a file, where do I add it?

Question: if I add a signal handler to a file, where do I add it?


Student question: what does setitimer do

Question: what does setitimer do


Student question: what is the input of malloc function

Question: what is the input of malloc function


Question: explain strcat


Question: what will strncat do?


Student question: what is the strlen of "\n"

Question: what is the strlen of "\n"


Question: what does snprintf do


Student question: asctime(localtime()), what does the return string looks like

Question: asctime(localtime()), what does the return string looks like


Student question: do we need to catch error for free()?

Question: do we need to catch error for free()?


Student question: server program and client program communicate via what?

Question: server program and client program communicate via what?


Code context (simplify for kids): \usepackage[margins=2.5]{geometry}


Student question: If I have float *x; and float y; how do I increase the amount stored in y by the amount in x?

Question: If I have float *x; and float y; how do I increase the amount stored in y by the amount in x?


Goal: add the value of x to the value of y | Code context (simplify for kids): int main(int argc, char **argv) { float x = 2.2; float *y; y = &x +1


Goal: return a count of ls -l file sizes larger than value parameter provided. If second parameter is 9 element permissions, the count is of files larger than first parameter that also match permissions. | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *permission, char *file) { for (int i = 0; i < 9; i++) { if (permission[i] != file[i]) { return 1; } } return 0; } int main(int argc, char** argv) {


Goal: return count of files larger than given parameter | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *permission, char *file) { for (int i = 0; i < 9; i++) { if (permission[i] != file[i]) { return 1; } } return 0; } int main(int argc, char** argv) {


Goal: it should return pow 3 when run with ./o powder 3 | Code context (simplify for kids): #include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters


Student question: Assign a dynamically allocate char* array of length 4 to variable called last_names

Question: Assign a dynamically allocate char* array of length 4 to variable called last_names


Student question: How to write a for loop in c for an array

Question: How to write a for loop in c for an array


Student question: allocate a character array of length 20 for each element of the array pointed to by last_names

Question: allocate a character array of length 20 for each element of the array pointed to by last_names


Student question: How do I allocate a character array of length 20 for each element of the array pointed to by last_names? | Code context (simplify for kids): #include <stdlib.h> #include <stdio.h> int main() { char **last_names; // Assign a dynamically allocated char * array of length 4 to last_names. // Then, allocate a character array of length 20 for each element of the array // pointed to by last_names. last_names = (char **) malloc(sizeof(char*)*4);

Question: How do I allocate a character array of length 20 for each element of the array pointed to by last_names?


Student question: allocate space on the heap for an array of 12 floats and assign it to the pointer monthly_rainfall

Question: allocate space on the heap for an array of 12 floats and assign it to the pointer monthly_rainfall


Student question: rainfall has been dynamically allocated space for a floating point number and initialized in hidden code. Add 7.6 to the amount currently stored in the space rainfall points to.

Question: rainfall has been dynamically allocated space for a floating point number and initialized in hidden code. Add 7.6 to the amount currently stored in the space rainfall points to.


Student question: Add 7.6 to the amount currently stored in the space rainfall points to.

Question: Add 7.6 to the amount currently stored in the space rainfall points to.


Student question: Increase the amount currently stored in total_rain by the amount stored in the space pointed to by rainfall.

Question: Increase the amount currently stored in total_rain by the amount stored in the space pointed to by rainfall.


Student question: set the allocated_amount variable to the exact amount of space that should be allocated and pointed to by float *rainfall

Question: set the allocated_amount variable to the exact amount of space that should be allocated and pointed to by float *rainfall


Student question: Assign the amount in rain_today to the space rainfall points to. | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { float *rainfall; float rain_today; // rainfall has been dynamically allocated space for a floating point number. // Both rainfall and rain_today have been initialized in hidden code. // Assign the amount in rain_today to the sp

Question: Assign the amount in rain_today to the space rainfall points to.


Goal: rain_today should be used. | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { float *rainfall; float rain_today; // rainfall has been dynamically allocated space for a floating point number. // Both rainfall and rain_today have been initialized in hidden code. // Assign the amount in rain_today to the sp


Student question: /* Returns the sum of two integers in the string input_line. input_line is a string containing two integers separated by one or more spaces. Assume that the string will not be more than 20 characters long and that it contains two integers separated only by whitespace. There may also be spaces before the first integer and/or after the last, but there won't be any other characters in the string. For

Question: /* Returns the sum of two integers in the string input_line. input_line is a string containing two integers separated by one or more spaces. Assume that the string will not be more than 20 characters long and that it contains two integers separated only by whitespace. There may also be spaces before the first integer and/or after the last, but there won't be any other characters in the string. For


Student question: return the sum of two integers in the string input_line using strtol().

Question: return the sum of two integers in the string input_line using strtol().


Code context (simplify for kids): * Returns the sum of two integers in the string input_line. input_line is a string containing two integers separated by one or more spaces. Assume that the string will not be more than 20 characters long and that it contains two integers separated only by whitespace. There may also be spaces before


Student question: Given three variables with hidden integer values, compare their values for uniqueness and print one of the following statements: - "none unique" (if all variables share the same value) - "some unique" (if exactly two variables share the same value) - "all unique" (if there are no duplicates)

Question: Given three variables with hidden integer values, compare their values for uniqueness and print one of the following statements: - "none unique" (if all variables share the same value) - "some unique" (if exactly two variables share the same value) - "all unique" (if there are no duplicates)


Student question: Write a for loop that prints the integers from 1 to 10 with spaces separating the values.

Question: Write a for loop that prints the integers from 1 to 10 with spaces separating the values.


Student question: Define a string literal named tasty with the value "doughnut".

Question: Define a string literal named tasty with the value "doughnut".


Student question: Set the value of delicious (which has already been declared) to "ice cream".

Question: Set the value of delicious (which has already been declared) to "ice cream".


Student question: The string sweet has been declared on the heap and has space for 20 characters. Set the value of sweet to "tiramisu" without changing its address.

Question: The string sweet has been declared on the heap and has space for 20 characters. Set the value of sweet to "tiramisu" without changing its address.