Student question: Is there any problem of this code? | Code context (simplify for kids): int main() { return 0; }

Question: Is there any problem of this code?


Student question: write a socket program that can transfer information

Question: write a socket program that can transfer information


Student question: do i need to free the pointer returned by ctime()

Question: do i need to free the pointer returned by ctime()


Student question: what is a static variable?

Question: what is a static variable?


Student question: What does this code do? | Code context (simplify for kids): int (*complex(int index))(char *s, int l);

Question: What does this code do?


Student question: Why does this code generate a seg fault | Code context (simplify for kids): 8 void fib(int **fib_sequence, int n) { 19 *fib_sequence = malloc(sizeof(int) * n); 20 for (int i = 0; i < n; i++) { 21 if (i < 2) { 22 *fib_sequence[i] = i; 23 } else { 24 *fib_sequence[i] = *fib_sequence[i - 2] + *fib_sequence[i - 1]; 25 } 26 } 27 }

Question: Why does this code generate a seg fault


Student question: Why does this code only look at the first argument of the list? | Code context (simplify for kids): int **split_array(const int *s, int length) { 14 int **main_array = malloc(sizeof(int *) * 2); 15 main_array[0] = malloc(sizeof(int) * length / 2); 16 main_array[1] = malloc(sizeof(int) * length / 2); 17 18 for (int i = 0; i < length; i++) { 19 if (i % 2 == 0) { 20 main_array[0][i] = s[i]; 21 } else

Question: Why does this code only look at the first argument of the list?


Goal: why does this overallocate memory on odd length arrays | Code context (simplify for kids): int **split_array(const int *s, int length) { int **main_array = malloc(sizeof(int *) * 2); main_array[0] = malloc(sizeof(int) * (length / 2 + length % 2)); main_array[1] = malloc(sizeof(int) * (length / 2)); for (int i = 0; i < length; i++) { if (i % 2 == 0) { main_array[0][i / 2] = s[i]; } else {


Goal: This code should allocate the correct amount of memory to each of the 2 arrays based on the length of the input array. For example, if the array is length 3, it should allocate sizeof(int) * 2 to the first array and sizeof(int) to the second | Code context (simplify for kids): int **split_array(const int *s, int length) { int **main_array = malloc(sizeof(int *) * 2); main_array[0] = malloc(sizeof(int) * (length / 2 + length % 2)); main_array[1] = malloc(sizeof(int) * (length / 2)); for (int i = 0; i < length; i++) { if (i % 2 == 0) { main_array[0][i / 2] = s[i]; } else {


Goal: For some reason, this is not correctly adding a new user to the list of users | Code context (simplify for kids): int create_user(const char *name, User **user_ptr_add) { 17 18 // Check the sizeof the name array 19 if (strlen(name) > 31) { 20 // Name is too long 21 return 2; 22 } 23 24 // Initialize a new user with name pointing to NULL 25 User new_user; 26 strcpy(new_user.name, name); 27 new_user.next = NULL;


Goal: How do I allocate memory when creating the user struct | Code context (simplify for kids): int create_user(const char *name, User **user_ptr_add) { 17 18 // Check the sizeof the name array 19 if (strlen(name) > 31) { 20 // Name is too long 21 return 2; 22 } 23 24 // Initialize a new user with name pointing to NULL 25 User new_user; 26 strcpy(new_user.name, name); 27 new_user.next = NULL;


Goal: Print the contents of an ASCII file | Code context (simplify for kids): char picture[MAX_NAME]; 262 FILE *profile = fopen(user->profile_pic, "r"); 263 fgets(picture, MAX_NAME, profile); 264 printf("%s\n", picture);


Goal: This code should print the entire file, but it only prints the first line | Code context (simplify for kids): char picture[MAX_NAME]; 262 FILE *profile = fopen(user->profile_pic, "r"); 263 fgets(picture, MAX_NAME, profile); 264 printf("%s", picture);


Goal: I am attempting to copy contents, which is type char * and allocated on the heap to contents, which is also type char * | Code context (simplify for kids): strcpy(new_post->contents, contents);


Goal: This should work just the same as strncpy | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { 16 17 int i; 18 for (i = 0; i < capacity && src[i] != '\0'; i++) { 19 dest[i] = src[i]; 20 } 21 22 for (; i < capacity; i++) { 23 dest[i] = '\0'; 24 } 25 26 return dest; 27 }


Goal: this code is meant to find the length of the string before the colon | Code context (simplify for kids): char *output; char *ptr = strchr(output, ':'); 32 33 // Copy the length of ptr - 1 to the target variable 34 int size = ptr - output;


Goal: this code is meant to find the length of the string before the colon | Code context (simplify for kids): char *output; char *ptr = strchr(output, ':'); 32 33 // Copy the length of ptr - 1 to the target variable 34 int size = ptr - output - 1;


Student question: This code is meant to tokenize a word off spaces and build a list of rules and dependencies. Currently, it only does one iteration | Code context (simplify for kids): char *dep = strtok(NULL, " "); Rule *rule_adder = curr; Dependency *curr_dep; while (dep != NULL) { // Allocate space for the dependency Dependency *new_dep = malloc(sizeof(Dependency)); if (rule_adder->dependencies == NULL) { rule_adder->dependencies = new_dep; curr_dep = rule_adder->dependencies;

Question: This code is meant to tokenize a word off spaces and build a list of rules and dependencies. Currently, it only does one iteration


Student question: *pt[2] is equal to what expression in C

Question: *pt[2] is equal to what expression in C


Student question: why *pt[2] = malloc(2 * size(int)) is invalid expression in C

Question: why *pt[2] = malloc(2 * size(int)) is invalid expression in C


Code context (simplify for kids): int **split_array(const int *s, int length) { int **pt; *pt = malloc(2 * sizeof(int *)); **pt = malloc((length / 2 ) * sizeof(int)); }


Code context (simplify for kids): int **split_array(const int *s, int length) { int **pt; *pt = malloc(2 * sizeof(int *)); pt = malloc((length / 2 ) * sizeof(int)); }


Goal: Check whether the pt has structure pt[2][length / 2] | Code context (simplify for kids): int **split_array(const int *s, int length) { int **pt; *pt = malloc(2 * sizeof(int *)); pt = malloc((length / 2 ) * sizeof(int)); }


Goal: why my racket program saying n unbound error | Code context (simplify for kids): (define (n-of n v) void) (if (zero? n) `() (cons(x xl) (n-of n-1 v)))


Student question: How to implement greedy algorithm

Question: How to implement greedy algorithm


Question: You only know C?


Student question: What is write in memory when run int I=5;

Question: What is write in memory when run int I=5;


Student question: how do I read in la -l input to my files without using pipes

Question: how do I read in la -l input to my files without using pipes


Student question: How do I prevent segfaults?

Question: How do I prevent segfaults?


Code context (simplify for kids): int main(int b,char**i){long long n=B,a=I^n,r=(a/b&a)>>4,y=atoi(*++i),_=(((a^n/b)*(y>>T)|y>>S)&r)|(a^r);printf("%.8s\n",(char*)&_);}


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


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


Student question: How much memory is allocated? | Code context (simplify for kids): int arr[];

Question: How much memory is allocated?


Student question: remove target_client from the linked list, client | Code context (simplify for kids): /* * Remove target_client from the given clients and free the memory. * Return the fd of the client if it was removed successfully. * Return 0 otherwise. */ int remove_client(Client *target_client, Client **clients){ Client *curr_client = *clients; // return 0 if the list is empty if (curr_client ==

Question: remove target_client from the linked list, client


Student question: how can i find length of int as a string

Question: how can i find length of int as a string


Question: How do i use asprintf


Student question: I've used malloc to allocate the memory in the heap for a local-scope variable, but that still gets destroyed after the function call. What went wrong?

Question: I've used malloc to allocate the memory in the heap for a local-scope variable, but that still gets destroyed after the function call. What went wrong?


Code context (simplify for kids): int on = 1; int status = setsockopt(soc, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)); if (status < 0) { perror("setsockopt"); exit(1); }


Code context (simplify for kids): if (bind(soc, (struct sockaddr *)self, sizeof(*self)) < 0) { // bind failed; could be because port is in use. perror("bind"); exit(1); }


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): struct sockaddr_in addr; // Allow sockets across machines. addr.sin_family = AF_INET; // The port the server will be listening on. addr.sin_port = htons(port); // Clear this field; sin_zero is used for padding for the struct. memset(&(addr.sin_zero), 0, 8); // Lookup host IP address. struct hostent


Student question: Accepted connection should be printed on line 181 | Code context (simplify for kids): int client_fd = accept(fd, NULL, NULL); if (client_fd < 0) { perror("server: accept"); close(fd); exit(1); } // If this is a valid user users[user_index].sock_fd = client_fd; users[user_index].username = NULL;

Question: Accepted connection should be printed on line 181


Code context (simplify for kids): char *string; char array1[5] = "Hola"; strncpy(string, array1, 5);


Student question: string should also be "Hola" | Code context (simplify for kids): char *string; char array1[5] = "Hola"; strncpy(string, array1, 5);

Question: string should also be "Hola"


Student question: string should be "Hola" | Code context (simplify for kids): char *string = malloc(5); char array1[5] = "Hola"; strncpy(string, array1, 5);

Question: string should be "Hola"


Code context (simplify for kids): setbuf(stdout, NULL);


Student question: What does socket() return upon success? | Code context (simplify for kids): int server_soc = socket(AF_INET, SOCK_STREAM, 0); if (server_soc < 0) { perror("Socket:"); }

Question: What does socket() return upon success?


Student question: Should I use select() for clients?

Question: Should I use select() for clients?


Student question: Should I use select() on client program?

Question: Should I use select() on client program?


Student question: Does 'return 0;' be read as 0 bytes for read()?

Question: Does 'return 0;' be read as 0 bytes for read()?


Question: what does FDSET() do?


Student question: Could I write nothing to write()?

Question: Could I write nothing to write()?


Student question: Should I specify the size of an array first before using asprintf?

Question: Should I specify the size of an array first before using asprintf?


Student question: When should I clean up an array of char?

Question: When should I clean up an array of char?


Student question: When should I use accept() when using select()?

Question: When should I use accept() when using select()?


Student question: Can a server manage multiple connections by calling 1 accept()?

Question: Can a server manage multiple connections by calling 1 accept()?


Student question: How to check which fd is ready to read with FD_ISSET()?

Question: How to check which fd is ready to read with FD_ISSET()?


Student question: How can FD_ISSET() tell which client fd is ready?

Question: How can FD_ISSET() tell which client fd is ready?


Student question: What does inet_pton() do?

Question: What does inet_pton() do?


Student question: What does FD_SET() do?

Question: What does FD_SET() do?


Student question: What does select() return?

Question: What does select() return?


Student question: how to tell which fd is ready to read after using select()?

Question: how to tell which fd is ready to read after using select()?


Student question: What members are in struct sockaddr_in?

Question: What members are in struct sockaddr_in?


Student question: What does connect() do to client socket fd?

Question: What does connect() do to client socket fd?


Student question: How do I know server socket fd via connect()?

Question: How do I know server socket fd via connect()?


Student question: How does connect() work on client socket?

Question: How does connect() work on client socket?


Student question: Does a client know a server fd after connect()?

Question: Does a client know a server fd after connect()?


Student question: Can I dereference a header to the null linked list in c?

Question: Can I dereference a header to the null linked list in c?


Student question: Can I always modify the size of waiting queue for listen()?

Question: Can I always modify the size of waiting queue for listen()?


Question: How to use execl()?


Student question: How to run execl on one process and receive the return on the other process?

Question: How to run execl on one process and receive the return on the other process?


Student question: How to use read() and write()?

Question: How to use read() and write()?


Student question: Is each element in argv[] separated by blank space?

Question: Is each element in argv[] separated by blank space?


Student question: When does read() return 0?

Question: When does read() return 0?


Student question: When does read() return 0 in socket programming?

Question: When does read() return 0 in socket programming?


Student question: Whatt does socket() return?

Question: Whatt does socket() return?


Student question: What does accept() take on the server side?

Question: What does accept() take on the server side?


Student question: Is accept() only be used on server side?

Question: Is accept() only be used on server side?


Student question: How can a client use accept()?

Question: How can a client use accept()?


Student question: How does a client use connect()?

Question: How does a client use connect()?


Student question: Does accept() return client fd upon success?

Question: Does accept() return client fd upon success?


Student question: If I malloc a whole struct, is every member of it also malloced?

Question: If I malloc a whole struct, is every member of it also malloced?


Student question: How do I get client fd in the waiting list from listen()?

Question: How do I get client fd in the waiting list from listen()?


Student question: How to loop over set_fd?

Question: How to loop over set_fd?


Student question: How to find the second largest fd in fd_set?

Question: How to find the second largest fd in fd_set?


Student question: Could FD_ISSET() prevent the program from being blocked by read()?

Question: Could FD_ISSET() prevent the program from being blocked by read()?


Student question: How to prevent a program from being blocked by accept()?

Question: How to prevent a program from being blocked by accept()?


Student question: How to reconnect a client to their previous client fd?

Question: How to reconnect a client to their previous client fd?


Student question: How to avoid redefinition from a header file?

Question: How to avoid redefinition from a header file?


Student question: How to avoid function redefinition from a header file?

Question: How to avoid function redefinition from a header file?


Student question: Can a server keep track of multiple client sockets at once after calling select() and FD_ISSET()?

Question: Can a server keep track of multiple client sockets at once after calling select() and FD_ISSET()?


Student question: Do I need to malloc an int member inside a struct?

Question: Do I need to malloc an int member inside a struct?


Question: Arguments of read()?


Student question: new_user->sock_fd should be assigned with int fd | Code context (simplify for kids): Usersockname *new_user = to_malloc(sizeof(Usersockname)); // to_malloc is from friends.c new_user->username = to_malloc(strlen(name) + 1); new_user->sock_fd = to_malloc(sizeof(int)); new_user->next = to_malloc(sizeof(Usersockname)); // There was a previous check on length size, so no need to recheck

Question: new_user->sock_fd should be assigned with int fd


Student question: Malloc but still cannot hold memory

Question: Malloc but still cannot hold memory


Student question: Is it a good idea to use malloc() inside a local scope?

Question: Is it a good idea to use malloc() inside a local scope?


Student question: How should I malloc the ptr to the first node of array list?

Question: How should I malloc the ptr to the first node of array list?


Student question: How should I malloc the double ptr to the first node of array list?

Question: How should I malloc the double ptr to the first node of array list?


Student question: When to use dup2() instead of pipe()?

Question: When to use dup2() instead of pipe()?


Student question: How to properly initialize an array of char without any garbage?

Question: How to properly initialize an array of char without any garbage?


Student question: How to avoid read() from reading a blank line?

Question: How to avoid read() from reading a blank line?


Student question: How to check for an empty line in C?

Question: How to check for an empty line in C?


Student question: Should I use fgets() in socket programming?

Question: Should I use fgets() in socket programming?


Student question: How to use strtok() to filter out empty line?

Question: How to use strtok() to filter out empty line?


Question: What does FD_SET do?


Student question: How can a server take care of multiple simultaneously requests from different clients at once?

Question: How can a server take care of multiple simultaneously requests from different clients at once?


Student question: I used select(), FD_SET() and FD_ISSET() but server still ignores upcoming requests

Question: I used select(), FD_SET() and FD_ISSET() but server still ignores upcoming requests


Student question: Should I malloc a char[]?

Question: Should I malloc a char[]?


Student question: When does read() return -1?

Question: When does read() return -1?


Student question: Will close(fd) also close the pipe?

Question: Will close(fd) also close the pipe?


Student question: Why FD_SET() does not add new fd into fd_set?

Question: Why FD_SET() does not add new fd into fd_set?


Student question: why double free or corruption (out) when I only free() for the first time?

Question: why double free or corruption (out) when I only free() for the first time?


Student question: When does free() gives corrupted error?

Question: When does free() gives corrupted error?


Student question: Could I copy a malloced string to a stack-allocated string?

Question: Could I copy a malloced string to a stack-allocated string?


Student question: Could I use strlen() on just dynamically allocated string without any input?

Question: Could I use strlen() on just dynamically allocated string without any input?


Student question: How to tell if a malloced string is empty or not?

Question: How to tell if a malloced string is empty or not?


Student question: Is all malloced string initialized with null characters?

Question: Is all malloced string initialized with null characters?


Student question: Does memset() affect malloced string?

Question: Does memset() affect malloced string?


Student question: Will strtok() return a stack-allocated string after tokenizing heap-allocated string?

Question: Will strtok() return a stack-allocated string after tokenizing heap-allocated string?


Student question: What does select() return where there is a signal from a client?

Question: What does select() return where there is a signal from a client?


Student question: How to know how many clients are talking via select() and FD_ISSET()?

Question: How to know how many clients are talking via select() and FD_ISSET()?


Student question: Should the server call accept() multiple times on the same client?

Question: Should the server call accept() multiple times on the same client?


Student question: How to use the fcntl() function with the O_NONBLOCK flag for non-blocking select() call?

Question: How to use the fcntl() function with the O_NONBLOCK flag for non-blocking select() call?


Student question: How should I use fcntl() in socket programming?

Question: How should I use fcntl() in socket programming?


Student question: How to use fcntl() with multiple fds?

Question: How to use fcntl() with multiple fds?


Student question: Why fcntl() leads to broken pipe?

Question: Why fcntl() leads to broken pipe?


Student question: How to make a server unblocking on read() call from multiple clients?

Question: How to make a server unblocking on read() call from multiple clients?


Student question: I used select() and FD_ISSET() but the server still blocks inputs from clients?

Question: I used select() and FD_ISSET() but the server still blocks inputs from clients?


Student question: What makes select() call knows a client is ready to read?

Question: What makes select() call knows a client is ready to read?


Student question: What is the point of using FD_ISSET() after select() call?

Question: What is the point of using FD_ISSET() after select() call?


Student question: How to make a read() call unblocking?

Question: How to make a read() call unblocking?


Question: How to use fcntl()?


Student question: How to know if the read() call is blocking?

Question: How to know if the read() call is blocking?


Student question: Is the server socket fd always set at 3?

Question: Is the server socket fd always set at 3?


Student question: is select() a blocking function?

Question: is select() a blocking function?


Student question: How to set out a timeout for select()?

Question: How to set out a timeout for select()?


Student question: what does select() return after being timed out?

Question: what does select() return after being timed out?


Student question: Why the server keeps ignoring clients' call even though using select(), FD_iSSET() and reset the set_fd to the original set_fd?

Question: Why the server keeps ignoring clients' call even though using select(), FD_iSSET() and reset the set_fd to the original set_fd?


Question: How to use FD_COPY()?


Student question: What are the parameters of FD_COPY()?

Question: What are the parameters of FD_COPY()?


Student question: How to copy a set_fd object?

Question: How to copy a set_fd object?


Student question: Does select() save the ready-to-read fd to its parameters?

Question: Does select() save the ready-to-read fd to its parameters?


Student question: How to print out every fd inside fd_set?

Question: How to print out every fd inside fd_set?


Student question: why does strtol need pointer to char array?

Question: why does strtol need pointer to char array?


Student question: What happens if I pass string of 0 to strtol?

Question: What happens if I pass string of 0 to strtol?


Student question: What happens if I pass a NULL endptr to strtol()?

Question: What happens if I pass a NULL endptr to strtol()?


Student question: Does strtol read negative values?

Question: Does strtol read negative values?


Student question: when does strtol return an error?

Question: when does strtol return an error?


Student question: Does strtol return an error if there is a non-numeric value in a string?

Question: Does strtol return an error if there is a non-numeric value in a string?


Student question: What happens if errno is not 0?

Question: What happens if errno is not 0?


Student question: Which process id pick up orphanage processes?

Question: Which process id pick up orphanage processes?


Student question: Is waitpid() a blocking function?

Question: Is waitpid() a blocking function?


Student question: Does waitpid return 0 mean that pid process is an orphan?

Question: Does waitpid return 0 mean that pid process is an orphan?


Student question: What return status of waitpid indicate that pid process is a zombie?

Question: What return status of waitpid indicate that pid process is a zombie?


Student question: How do we call pipe in C?

Question: How do we call pipe in C?


Student question: When does pipe() return -1?

Question: When does pipe() return -1?


Student question: Is a newer pid always greater than the older ones?

Question: Is a newer pid always greater than the older ones?


Student question: Are system calls returning -1 as errors?

Question: Are system calls returning -1 as errors?


Student question: What happens if I close a closed fd?

Question: What happens if I close a closed fd?


Student question: What happens if I close a non-existent fd?

Question: What happens if I close a non-existent fd?


Student question: How to close all previously forked children processes?

Question: How to close all previously forked children processes?


Student question: Why do I need to pass in ptr to read() and write() call?

Question: Why do I need to pass in ptr to read() and write() call?


Student question: What does buffer do in write() and read()?

Question: What does buffer do in write() and read()?


Student question: What does buffer do in read()?

Question: What does buffer do in read()?


Student question: When does waitpid() return -1?

Question: When does waitpid() return -1?


Student question: How to use WNOHANG with waitpid()?

Question: How to use WNOHANG with waitpid()?


Student question: Why does wait() need a ptr to status?

Question: Why does wait() need a ptr to status?


Student question: Use wait() with WIFEXITED and WEXITSTATUS

Question: Use wait() with WIFEXITED and WEXITSTATUS


Student question: What argument does WEIXTSTATUS take?

Question: What argument does WEIXTSTATUS take?


Student question: What argument does WEXITSTATUS take?

Question: What argument does WEXITSTATUS take?


Question: open() vs. fopen()?


Student question: What does dup2() do in C?

Question: What does dup2() do in C?


Question: How to use execl()?


Student question: What are the parameters of waitpid()?

Question: What are the parameters of waitpid()?


Student question: sigaddset() and sigemptyset() in C?

Question: sigaddset() and sigemptyset() in C?


Question: sigprocmask()?


Student question: Does sigprocmask() block a signal from reaching a process?

Question: Does sigprocmask() block a signal from reaching a process?


Student question: What does sigprocmask()?

Question: What does sigprocmask()?


Student question: what does SIG_BLOCK do?

Question: what does SIG_BLOCK do?


Student question: What does SIG_SETMASK do?

Question: What does SIG_SETMASK do?


Student question: Can you use the `sigprocmask()` function to check if a signal is currently blocked or unblocked in your program?

Question: Can you use the `sigprocmask()` function to check if a signal is currently blocked or unblocked in your program?


Student question: When to fill out oldset in sigcpromask()?

Question: When to fill out oldset in sigcpromask()?


Student question: Does an oldset and set in setprocmask()?

Question: Does an oldset and set in setprocmask()?


Student question: What do oldset and set contain in sigprocmask()?

Question: What do oldset and set contain in sigprocmask()?


Student question: What is a signal mask?

Question: What is a signal mask?


Student question: What does struct sigaction do?

Question: What does struct sigaction do?


Student question: What does sigaction() do in C?

Question: What does sigaction() do in C?


Student question: What defines as a user-defined signal or SIGUSR?

Question: What defines as a user-defined signal or SIGUSR?


Student question: Difference between signal() and sigaction()?

Question: Difference between signal() and sigaction()?


Student question: Could sigaction() be used to unblock a masked signal?

Question: Could sigaction() be used to unblock a masked signal?


Student question: Could sigaction() be used to modify sa_handler of struct sigaction?

Question: Could sigaction() be used to modify sa_handler of struct sigaction?


Student question: Is sigaction() be used to update the system behavior according to the members of the given struct sigaction?

Question: Is sigaction() be used to update the system behavior according to the members of the given struct sigaction?


Student question: What is the purpose of signum in sigaction()?

Question: What is the purpose of signum in sigaction()?


Student question: Could I use sigaddset() instead of passing a signum into sigaction()?

Question: Could I use sigaddset() instead of passing a signum into sigaction()?


Student question: What are the members of ps_set?

Question: What are the members of ps_set?


Student question: What does PS_ISSET() do?

Question: What does PS_ISSET() do?


Student question: Difference between PS_ZERO and PS_CLEAR?

Question: Difference between PS_ZERO and PS_CLEAR?


Student question: Difference between PS_ZERO and PS_CLR?

Question: Difference between PS_ZERO and PS_CLR?


Student question: What does expr do in shell programming?

Question: What does expr do in shell programming?


Student question: ` ` in shell programming

Question: ` ` in shell programming


Student question: Could I use ` instead of expr in shell programming?

Question: Could I use ` instead of expr in shell programming?


Question: What does shebang do?


Student question: What does an intepreter do in shell programming?

Question: What does an intepreter do in shell programming?


Student question: What does grep do in shell programming?

Question: What does grep do in shell programming?


Student question: Does test in shell programming used for checking for conditional if?

Question: Does test in shell programming used for checking for conditional if?


Student question: Could test replace expr in shell programming?

Question: Could test replace expr in shell programming?


Student question: What does match of expr do in shell programming?

Question: What does match of expr do in shell programming?


Student question: What does bind() do in socket programming?

Question: What does bind() do in socket programming?


Student question: Is the socket file descriptor remaining consistent throughout multiple calls of bind() with the given socket()?

Question: Is the socket file descriptor remaining consistent throughout multiple calls of bind() with the given socket()?


Student question: What does the socket file descriptor outputted by socket() contain?

Question: What does the socket file descriptor outputted by socket() contain?


Student question: What does it mean when saying socket file descriptor is the same as file descriptor?

Question: What does it mean when saying socket file descriptor is the same as file descriptor?


Student question: Why the socket file descriptor given by socket() must be reused for subsequent bind() calls?

Question: Why the socket file descriptor given by socket() must be reused for subsequent bind() calls?


Student question: Does any socket file descriptor have to have the port of the server?

Question: Does any socket file descriptor have to have the port of the server?


Student question: = vs. \eq in shell programming?

Question: = vs. \eq in shell programming?


Student question: Does == exist in shell programming?

Question: Does == exist in shell programming?


Student question: How to compare two different integers in shell programming besides \eq?

Question: How to compare two different integers in shell programming besides \eq?


Student question: How to check two integers are equal besides \eq in shell programming?

Question: How to check two integers are equal besides \eq in shell programming?


Student question: Does test always require two operands?

Question: Does test always require two operands?


Student question: Why does ambiguous redirect output in shell programming?

Question: Why does ambiguous redirect output in shell programming?


Student question: What does ls | wc do in shell programming?

Question: What does ls | wc do in shell programming?


Student question: What counts as a line in wc in shell programming?

Question: What counts as a line in wc in shell programming?


Student question: f | Code context (simplify for kids): #!/ bin / bash for arg in "$@" do #If you want the shared version / u / csc209h / winter / pub / shell - prog / fibonacci "$arg" done

Question: f


Student question: When does waitpid() immediately return?

Question: When does waitpid() immediately return?


Student question: Is it true that connect() can be blocked when the listen queue is full?

Question: Is it true that connect() can be blocked when the listen queue is full?


Student question: When does fseek() return -1?

Question: When does fseek() return -1?


Question: What does fseek() do?


Question: How to copy a struct?


Student question: How does fwrite() work?

Question: How does fwrite() work?


Student question: What are the parameters of fread()?

Question: What are the parameters of fread()?


Student question: What are the flags of wc in shell programming?

Question: What are the flags of wc in shell programming?


Student question: What does pipe do in the code? | Code context (simplify for kids): ../ my_prog | wc - l > outputfile

Question: What does pipe do in the code?


Student question: Why are there two dots at the beginning? | Code context (simplify for kids): ../ my_prog | wc - l > outputfile

Question: Why are there two dots at the beginning?


Student question: What are the parameters of fread()?

Question: What are the parameters of fread()?


Student question: When piping is needed in shell programming?

Question: When piping is needed in shell programming?


Student question: When to use (()) in shell programming?

Question: When to use (()) in shell programming?


Student question: Can I use (()) instead of expr in shell programming?

Question: Can I use (()) instead of expr in shell programming?


Student question: Does (()) work on string operator?

Question: Does (()) work on string operator?


Student question: Is it good to leave an extra space for null terminator when mallocing a char ptr?

Question: Is it good to leave an extra space for null terminator when mallocing a char ptr?


Question: When to use htons()?


Student question: Is a string literal always null terminated?

Question: Is a string literal always null terminated?


Student question: Are all memory blocks in heap initialized to \0 at first?

Question: Are all memory blocks in heap initialized to \0 at first?


Student question: What are the parameters of fscanf()?

Question: What are the parameters of fscanf()?


Student question: Parameters of strtol()?

Question: Parameters of strtol()?


Student question: Can you give usage of fprintf()?

Question: Can you give usage of fprintf()?


Student question: Could I use strlen on newly created array?

Question: Could I use strlen on newly created array?


Student question: Why can't I strncpy \0 into a string?

Question: Why can't I strncpy \0 into a string?


Student question: How to set null terminator in a char pointer?

Question: How to set null terminator in a char pointer?


Student question: Could I append null terminator with strncat()?

Question: Could I append null terminator with strncat()?


Student question: Do I need to append null terminator at the end of a string literal?

Question: Do I need to append null terminator at the end of a string literal?


Student question: How to make sure every string literal is always null terminated?

Question: How to make sure every string literal is always null terminated?


Student question: Do I need to add +1 in strncat()?

Question: Do I need to add +1 in strncat()?


Student question: Does strncat add null terminators on the leftover indexes of a string?

Question: Does strncat add null terminators on the leftover indexes of a string?


Student question: Does a string after strncat() always be null terminated if there's extra space left at the end?

Question: Does a string after strncat() always be null terminated if there's extra space left at the end?


Student question: What does WIFEXITED(status) return?

Question: What does WIFEXITED(status) return?


Student question: Why does a newly created ptr do not have any initialized value?

Question: Why does a newly created ptr do not have any initialized value?


Student question: What does socket() do?

Question: What does socket() do?


Student question: What is the difference between socket domain and socket type?

Question: What is the difference between socket domain and socket type?


Student question: Is it true that a port can only be reserved for one client to talk to their server?

Question: Is it true that a port can only be reserved for one client to talk to their server?


Student question: Could I use dup() or dup2() on closed file fd?

Question: Could I use dup() or dup2() on closed file fd?


Student question: What does while(1); do?

Question: What does while(1); do?


Student question: How do I do kill in shell programming to end one's program activity?

Question: How do I do kill in shell programming to end one's program activity?


Student question: What are flags of kill in shell programming?

Question: What are flags of kill in shell programming?


Student question: What does this code do? | Code context (simplify for kids): ./ myprog<test$i.in> actual$i.out

Question: What does this code do?


Student question: Does waitpid() accept WNOHANG?

Question: Does waitpid() accept WNOHANG?


Student question: What is -a in shell programming?

Question: What is -a in shell programming?


Student question: What does ${} do in shell programming?

Question: What does ${} do in shell programming?


Student question: Would if test 1 get passed into then block in shell programming?

Question: Would if test 1 get passed into then block in shell programming?


Student question: What is the difference between "$parameter" and "${parameter}"?

Question: What is the difference between "$parameter" and "${parameter}"?


Student question: What are special characters that I need to put \ before them in double quote in shell programming?

Question: What are special characters that I need to put \ before them in double quote in shell programming?


Student question: Could I use "${parameter}" instead of "$parameter"?

Question: Could I use "${parameter}" instead of "$parameter"?


Student question: What does the first line do? | Code context (simplify for kids): for i in *; do echo $i is a file done

Question: What does the first line do?


Student question: Why there is a semicolon on line 1? | Code context (simplify for kids): for i in *; do echo $i is a file done

Question: Why there is a semicolon on line 1?


Student question: How to get the current directory in shell programming?

Question: How to get the current directory in shell programming?


Student question: What does : do in a block in shell programming?

Question: What does : do in a block in shell programming?


Student question: What does extern do in header files?

Question: What does extern do in header files?


Student question: Could I use static variables in header files?

Question: Could I use static variables in header files?


Student question: Can I compile more than one file with main() inside a makefile?

Question: Can I compile more than one file with main() inside a makefile?


Student question: can I send a signal to a process that is neither a parent nor a child of the current process?

Question: can I send a signal to a process that is neither a parent nor a child of the current process?


Student question: Are open descriptors not inherited across an exec() call?

Question: Are open descriptors not inherited across an exec() call?


Student question: Are memory addresses not inherited across an exec() call?

Question: Are memory addresses not inherited across an exec() call?


Student question: Could I dereference out-of-bound index?

Question: Could I dereference out-of-bound index?


Student question: How to check if a binary representation is a negative number?

Question: How to check if a binary representation is a negative number?


Student question: Where is the sign bit in binary representation?

Question: Where is the sign bit in binary representation?


Student question: How to copy an array of characters?

Question: How to copy an array of characters?


Student question: redir in shell programming?

Question: redir in shell programming?


Student question: When to update max_fd in socket programming?

Question: When to update max_fd in socket programming?


Student question: What happens if I initialized the members of a struct with values in a wrong way?

Question: What happens if I initialized the members of a struct with values in a wrong way?


Student question: Name the three (3) categories that most preprocessing directives fall into

Question: Name the three (3) categories that most preprocessing directives fall into


Student question: What are the three categories most of C preprocessors are categorized as?

Question: What are the three categories most of C preprocessors are categorized as?


Student question: What is the point of calling fclose() when program will end anyway?

Question: What is the point of calling fclose() when program will end anyway?


Student question: What are 2 similarities between pipes and files?

Question: What are 2 similarities between pipes and files?


Student question: How do I initialize an array of char?

Question: How do I initialize an array of char?


Student question: How to identify if a process is a zombie?

Question: How to identify if a process is a zombie?


Question: What does ps aux do?


Student question: How does ps differ from ps aux?

Question: How does ps differ from ps aux?


Student question: Are System calls C programs' interface to the operating system and the computer’s hardware?

Question: Are System calls C programs' interface to the operating system and the computer’s hardware?


Student question: Is it true that a server may read and write to multiple clients on the same socket?

Question: Is it true that a server may read and write to multiple clients on the same socket?


Student question: Is it true that Makefile will exit with an error if the target of a rule is not a file?

Question: Is it true that Makefile will exit with an error if the target of a rule is not a file?


Student question: Are all dependencies in a Makefile files?

Question: Are all dependencies in a Makefile files?


Goal: phone should save the first 11 char from the input, which is followed by a number | Code context (simplify for kids): char phone[11]; int num; scanf("%s%d", phone, num);


Code context (simplify for kids): int length = 0; int num = 298475 for (int i = 10; i > 10; i*10) { num -= (num % i); length ++ }


Code context (simplify for kids): int c = 1; int a = c;


Code context (simplify for kids): int x = 123; if (x / 10 == 12){ printf("yay"); }


Code context (simplify for kids): int x = 128; if (x / 10 == 12){ printf("yay"); }


Goal: count the number of digits in copy | Code context (simplify for kids): int copy = 123456789; int length = 1; for (int i = 10; copy > 10; i * 10){ copy -= copy % i; // turning every digit to 0 length += 1; }


Code context (simplify for kids): printf("check: %d \n", sin % (10^1));


Code context (simplify for kids): printf("check: %d \n", 123456789 % (10^1));


Code context (simplify for kids): int sin = 123456789; for (int i = 0; i < 9; i ++) { printf("sin: %d \n", sin); int digit = (sin % (10^(1+i))); printf("digit: %d \n", digit); sin -= digit * 10^i; sin_array[8 - i] = digit // dividing by 10 drops the decimals printf("array: %d \n", sin_array[8 - i]); }


Code context (simplify for kids): int sin = 123456789; for (int i = 0; i < 9; i ++) { printf("sin: %d \n", sin); int digit = (sin % (10^(1+i))); printf("digit: %d \n", digit); sin -= digit * 10^i; sin_array[8 - i] = digit; // dividing by 10 drops the decimals printf("array: %d \n", sin_array[8 - i]); }


Goal: should take each digit in sin and place it in sin_array at the corresponding index | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> int main() { int sin = 123456789; int sin_array[9]; int digit; for (int i = 0; i < 9; i ++) { digit = sin % (10^(1+i)); printf("digit: %d \n", digit); sin -= digit * 10^i; sin = sin / 10; sin_array[8 - i] = digit; } }


Goal: if length of the string is greater than the amount given, then truncate the string to be of length amount and return the number of chars removed | Code context (simplify for kids): if (strlen(str) > amount) { // truncate str at amount characters str[amount] = '\0'; return (strlen(str) - amount); } return 0;


Goal: save length of an array called friends that's saved in struct called current | Code context (simplify for kids): struct *current; int length = sizeof(*(current->friends))/sizeof(*(current->friends)[0]);


Student question: What is the line to compile it into an executable named a.out that it will print the value 5 to stdout? | 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?


Student question: in the program. 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: in the program. What will this declaration line become after the program has passed through the C pre-processor?


Student question: why does the third line make w[1] = "ello"? | Code context (simplify for kids): char **w = malloc(2 * sizeof(char *)); w[0] = "hello"; *(w + 1) = w[0] + 1; printf("%s, %s", w[0], w[1]);

Question: why does the third line make w[1] = "ello"?


Student question: how can you tell the difference between compiling and run time error

Question: how can you tell the difference between compiling and run time error


Code context (simplify for kids): char *names[2];


Student question: which takes precedence, * or [2] | Code context (simplify for kids): char *names[2];

Question: which takes precedence, * or [2]


Question: fscanf vs fread?


Student question: is this run time or compiling error | Code context (simplify for kids): char *film = "Moonlight";  NO ERROR char x; x = film;  RUN-TIME ERROR x[0] = ’L’;

Question: is this run time or compiling error


Student question: is this run time or compiling error | Code context (simplify for kids): char *film = "Moonlight"; char x; x = film; x[0] = ’L’;

Question: is this run time or compiling error


Student question: why is this a run time error | Code context (simplify for kids): int *mkpoint(int x, int y) { int pt[2] = {x, y}; return pt; } int *x; x = mkpoint(3, 4);

Question: why is this a run time error


Student question: how do we make sure the new children don't create additional processes | Code context (simplify for kids): for (int i = 0; i < iterations; i++) { int n = fork(); if (n < 0) { perror("fork"); exit(1); } printf("ppid = %d, pid = %d, i = %d\n", getppid(), getpid(), i); }

Question: how do we make sure the new children don't create additional processes


Student question: how do we make sure that when process only creates one child and control the total number of processes | Code context (simplify for kids): for (int i = 0; i < iterations; i++) { if (created == 0){ int created = fork(); if (created < 0) { perror("fork"); exit(1); } else if (created > 0) { wait(&waitstatus); } } printf("ppid = %d, pid = %d, i = %d\n", getppid(), getpid(), i); }

Question: how do we make sure that when process only creates one child and control the total number of processes


Student question: why does the parent process fork 2 processes? | Code context (simplify for kids): int main() { int iterations = 2; int created = 0; int n = 0; for (int i = 0; i < iterations; i++) { if (created == 0){ int created = fork(); if (created < 0) { perror("fork"); exit(1); } else if(created > 0) { wait(&n); } } printf("ppid = %d, pid = %d, i = %d\n", getppid(), getpid(), i); } return 0;

Question: why does the parent process fork 2 processes?


Student question: why does the parent process fork 2 processes when created changes to a non 0 value | Code context (simplify for kids): int main() { int iterations = 2; int created = 0; int n = 0; for (int i = 0; i < iterations; i++) { if (created == 0){ int created = fork(); if (created < 0) { perror("fork"); exit(1); } else if(created > 0) { wait(&n); } } printf("ppid = %d, pid = %d, i = %d\n", getppid(), getpid(), i); } return 0;

Question: why does the parent process fork 2 processes when created changes to a non 0 value


Student question: why is it the validate file asks for input from stdin in the form: <username> \n <password> \n but this code asks for input in the form: <username> \n <password> \n \n \n \n? How do I fix this? | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> // NOTE: MAX_PASSWORD must be less than MAXLINE/2 #define MAXLINE 32 #define MAX_PASSWORD 10 #define PASSWORD_FILE "pass.txt" /* Reads two chunks from stdin, and checks if they match a user id * and password pair from a p

Question: why is it the validate file asks for input from stdin in the form: <username> \n <password> \n but this code asks for input in the form: <username> \n <password> \n \n \n \n? How do I fix this?


Student question: what would this print | Code context (simplify for kids): int main() { char *str; strncat(str, "hello", 3); printf("%s\n", str); return 0; }

Question: what would this print


Student question: what would this print | Code context (simplify for kids): int main() { char *str; strncpy(str, "hello", 3); printf("%s\n", str); return 0; }

Question: what would this print


Question: how to use strtok()


Student question: is the tab ('\t') included in the first token? If so, how do I get rid of it? | Code context (simplify for kids): int main () { char str[100] = "\tgcc -Wall -g -std=gnu99 -c shit.c"; const char s[2] = " "; char *token; /* get the first token */ token = strtok(str, s); /* walk through other tokens */ while(token != NULL ) { printf( "\n%s", token ); token = strtok(NULL, s); } return(0); }

Question: is the tab ('\t') included in the first token? If so, how do I get rid of it?


Student question: if you tokenize a str, what is strlen(token)?

Question: if you tokenize a str, what is strlen(token)?


Task: how to get number of tokens from strtok


Student question: does this give me the str removing '\t'? | Code context (simplify for kids): strchr(tokens, '\t') + 1;

Question: does this give me the str removing '\t'?


Student question: if you have array = char[][], what does strlen(array) give you

Question: if you have array = char[][], what does strlen(array) give you


Student question: If you have double array = char[x][y], how do you find the x number? | Code context (simplify for kids): strchr(tokens, '\t') + 1;

Question: If you have double array = char[x][y], how do you find the x number?


Student question: If you have double array = char[x][y], how do you find the x number?

Question: If you have double array = char[x][y], how do you find the x number?


Task: c how to print 2d array when you dont know the dimensions


Task: how do I while loop through a 2d char array to print each word in the array


Task: how do I assign space for 2d array using malloc


Student question: why does the *char give error | Code context (simplify for kids): char **args = malloc(sizeof(*char) * len);

Question: why does the *char give error


Student question: why does this give error and how do I fix it? | Code context (simplify for kids): fread(line, MAXLINE, sizeof(char), fp); while (line != EOF) {

Question: why does this give error and how do I fix it?


Student question: why does this line of code give error | Code context (simplify for kids): char *tokens = strtok(rest_of_line, ' ');

Question: why does this line of code give error


Student question: why does this give error | Code context (simplify for kids): char *line; fgets(line, MAXLINE, fp);

Question: why does this give error


Student question: how to run gdb for a file that doesn't have a main function? And how do I use gdb with input files (the code I want to debug needs an input file)?

Question: how to run gdb for a file that doesn't have a main function? And how do I use gdb with input files (the code I want to debug needs an input file)?


Student question: wen I use gdb: "gdb pmake.c < handout_example/handout.mk" I get there error: "not in executable format: file format not recognized".

Question: wen I use gdb: "gdb pmake.c < handout_example/handout.mk" I get there error: "not in executable format: file format not recognized".


Student question: when I use gdb: "gdb pmake < handout_example/handout.mk" I get there error: "not in executable format: file format not recognized".

Question: when I use gdb: "gdb pmake < handout_example/handout.mk" I get there error: "not in executable format: file format not recognized".


Student question: when I use gdb: "gdb pmake < handout_example/handout.mk" I get there error: "not in executable format: file format not recognized". pmake has already been compiled by gcc

Question: when I use gdb: "gdb pmake < handout_example/handout.mk" I get there error: "not in executable format: file format not recognized". pmake has already been compiled by gcc


Student question: when I use gdb: "gdb pmake < handout_example/handout.mk" I get there error: "not in executable format: file format not recognized". pmake has already been compiled by gcc -g

Question: when I use gdb: "gdb pmake < handout_example/handout.mk" I get there error: "not in executable format: file format not recognized". pmake has already been compiled by gcc -g


Student question: should strncpy's last argument be strlen(token) or strlen(token) + 1 if strlen(token) = number of letters I want to copy (not include null terminator) | Code context (simplify for kids): char **args = mallo(sizeof(char *) * len); for (int i = 0; i < len; i++) { args[i] = malloc(sizeof(char) * strlen(token) + 1); strncpy(args[i], token, strlen(token)); }

Question: should strncpy's last argument be strlen(token) or strlen(token) + 1 if strlen(token) = number of letters I want to copy (not include null terminator)


Student question: how do I check if 2 chars are equal (I want to check if the first char in a string is a tab)

Question: how do I check if 2 chars are equal (I want to check if the first char in a string is a tab)


Student question: Assume all function calls from nonstandard c libraries are helpers that work perfectly. This program is meant to create Node structures to organize make files. There's a function that prints the structure in a format to mimic a make file on standard output. But when I call on the corresponding print function in my terminal, it just keeps asking for input and I can't exit out (I have to kill termin | Code context (simplify for kids): Rule *parse_file(FILE *fp) { Rule *target_cur; Rule *target_head = NULL; Rule *other_head = NULL; char line[MAXLINE]; fgets(line, MAXLINE, fp); while (line != NULL) { if (is_comment_or_empty(line) == 1) { // line is empty or is a comment } else if (strchr(line, ':') != NULL) { // line contains start

Question: Assume all function calls from nonstandard c libraries are helpers that work perfectly. This program is meant to create Node structures to organize make files. There's a function that prints the structure in a format to mimic a make file on standard output. But when I call on the corresponding print function in my terminal, it just keeps asking for input and I can't exit out (I have to kill termin


Student question: when I call strtok twice in a row on the same line, it gives me segmentation fault the second time around. How to I mitigate this so I can call strtok again?

Question: when I call strtok twice in a row on the same line, it gives me segmentation fault the second time around. How to I mitigate this so I can call strtok again?


Student question: the first print statement prints but the following print statements don't instead, the terminal screen goes blank. What causes this error? | Code context (simplify for kids): if (strncmp(line, "\t", sizeof(char)) == 0) { printf("enter into action line \n"); // line starts with tab, AKA contains actions (should mitigate the \r\n issues, I had 'else' before) char *copy = strdup(line); char *tokens = strtok(copy, " "); int len = 0; while (tokens != NULL) { printf("token: %s

Question: the first print statement prints but the following print statements don't instead, the terminal screen goes blank. What causes this error?


Student question: what function can I use to count the number of tokens there are after calling strtok

Question: what function can I use to count the number of tokens there are after calling strtok


Student question: is there a function that returns the number occurences of a char within a string?

Question: is there a function that returns the number occurences of a char within a string?


Student question: I run a file with terminal command: ./pmake -f handout.mk -o, where -f and -o are defined in pmake.c, handout.mk is a file in the same folder, and pmake is compiled from pmake.c How do I run gdb to test this exact input?

Question: I run a file with terminal command: ./pmake -f handout.mk -o, where -f and -o are defined in pmake.c, handout.mk is a file in the same folder, and pmake is compiled from pmake.c How do I run gdb to test this exact input?


Student question: im running gdb and when I write display <variable> where variable is a string from a file, gdb displays it in binary. Is there a way to have gdb display the variable in human readable text?

Question: im running gdb and when I write display <variable> where variable is a string from a file, gdb displays it in binary. Is there a way to have gdb display the variable in human readable text?


Student question: in gdb, how do I go back a line?

Question: in gdb, how do I go back a line?


Student question: I'm trying to remove the rest of the string line starting from '\r', but this gives me warnings when I compile. Why, and how do I fix this? | Code context (simplify for kids): char *ptr = strchr(line, '\r'); ptr = '\0';

Question: I'm trying to remove the rest of the string line starting from '\r', but this gives me warnings when I compile. Why, and how do I fix this?


Student question: when I run the code this is the warning that pops up in gcc warning: null argument where non-null required (argument 2) [-Wnonnull] 206 | strcpy(ptr, '\0'); what does it mean and how do i fix this? | Code context (simplify for kids): char *ptr = strchr(line, '\r'); strcpy(ptr, '\0');

Question: when I run the code this is the warning that pops up in gcc warning: null argument where non-null required (argument 2) [-Wnonnull] 206 | strcpy(ptr, '\0'); what does it mean and how do i fix this?


Student question: why doesn't this code print "outside 7" to standard 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: why doesn't this code print "outside 7" to standard error?


Student question: how do I remove whitespace from a string

Question: how do I remove whitespace from a string


Student question: how do I remove whitespace from a string without strtok

Question: how do I remove whitespace from a string without strtok


Student question: how to use struct stat to compare the last modified times of two files

Question: how to use struct stat to compare the last modified times of two files


Student question: the code is meant to execute rules from a make file in parallel by having the parent create a child for each dependency. When compiled, the perror on line 29 runs. Why, and how do I fix this? | Code context (simplify for kids): void parallel_eval(Rule *rule) { Dependency *dep_cur = rule->dependencies; int parentPID = getpid(); while (dep_cur != NULL) { // create a child proccess for each dependency if (parentPID == getpid()) { // parent int n = fork(); if (n < 0) { perror("Error: forking\n"); exit(1); } if (n == 0) { // ch

Question: the code is meant to execute rules from a make file in parallel by having the parent create a child for each dependency. When compiled, the perror on line 29 runs. Why, and how do I fix this?


Student question: I tried logging in to a linux server and this error popped up on the terminal : PTY allocation request failed on channel 0. Any idea what caused this?

Question: I tried logging in to a linux server and this error popped up on the terminal : PTY allocation request failed on channel 0. Any idea what caused this?


Student question: if the file that rule refers to has never been compiled, what does this function return? | Code context (simplify for kids): int compare_time(Rule *rule) { struct stat target_stat; Dependency *dep_cur = rule->dependencies; if (stat(rule->target, &target_stat) < 0) { // target file was never executed, so need to run actions return 1; } return 0; }

Question: if the file that rule refers to has never been compiled, what does this function return?


Student question: assume the file that rule refers to has never been compiled. But the function keeps returning 1 when I run it. What could be causing the problem? | Code context (simplify for kids): int compare_time(Rule *rule) { struct stat target_stat; Dependency *dep_cur = rule->dependencies; if (stat(rule->target, &target_stat) < 0) { // target file was never executed, so need to run actions return 1; } while (dep_cur != NULL) { struct stat check_stat; stat(dep_cur->rule->target, &check_sta

Question: assume the file that rule refers to has never been compiled. But the function keeps returning 1 when I run it. What could be causing the problem?


Student question: Question: assume the file that rule refers to has never been compiled. But the function keeps returning 0 when I run it. What could be causing the problem? | Code context (simplify for kids): int compare_time(Rule *rule) { struct stat target_stat; Dependency *dep_cur = rule->dependencies; if (stat(rule->target, &target_stat) < 0) { // target file was never executed, so need to run actions return 1; } while (dep_cur != NULL) { struct stat check_stat; stat(dep_cur->rule->target, &check_sta

Question: Question: assume the file that rule refers to has never been compiled. But the function keeps returning 0 when I run it. What could be causing the problem?


Student question: Why do I get this error: think the intro and conclusion of the internal validity section can be combined into the first and last examples. ? | Code context (simplify for kids): struct sigaction action; action.sa_handler = handler; sigemptyset(&action.sa_mask); action.sa_flags = 0; sigaction(SIGPROF, &action, NULL);

Question: Why do I get this error: think the intro and conclusion of the internal validity section can be combined into the first and last examples. ?


Student question: Why do I get this error: "incomplete type is not allowed" for the variable "action"? | Code context (simplify for kids): struct sigaction action; action.sa_handler = handler; sigemptyset(&action.sa_mask); action.sa_flags = 0; sigaction(SIGPROF, &action, NULL);

Question: Why do I get this error: "incomplete type is not allowed" for the variable "action"?


Task: 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: Variable x has been assigned a digit between 1 and 10. How do I 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. How do I write a shell command to calculate x minus 1 and display the result to standard output.


Student question: Variable x has been assigned a digit between 1 and 10. Write a sh 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 sh shell command to calculate x minus 1 and display the result to standard output.


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


Student question: I'm trying to use expr in shell command but when I use * for multiplication, I get an error. What's the problem?

Question: I'm trying to use expr in shell command but when I use * for multiplication, I get an error. What's the problem?


Student question: if i call read(fd, &buf, BUF_SIZE); does read concatonate onto buf or does it overwrite buf?

Question: if i call read(fd, &buf, BUF_SIZE); does read concatonate onto buf or does it overwrite buf?


Student question: should malloc be assigned sizeof(char) * num_read or sizeof(char) * (1 + num_read) ? | Code context (simplify for kids): int num_read = read(fd, &buf, BUF_SIZE); buf[num_read] = '\0'; users[client_index].username = malloc(sizeof(char) * num_read);

Question: should malloc be assigned sizeof(char) * num_read or sizeof(char) * (1 + num_read) ?


Student question: after using malloc, do I have to explicitly set the name[strlen(username)] = '\0' ? | Code context (simplify for kids): char *name = malloc(sizeof(char) * (strlen(username) + 1)); strncpy(client->username, name, strlen(name));

Question: after using malloc, do I have to explicitly set the name[strlen(username)] = '\0' ?


Student question: the code is supposed to create a string name from the contents of username and allocate memory in the heap. However, when I run the code through gdb, name = "". What is causing this error? | Code context (simplify for kids): char *name = malloc(sizeof(char) * (strlen(username) + 1)); name[strlen(username)] = '\0'; strncpy(client->username, name, strlen(name) + 1);

Question: the code is supposed to create a string name from the contents of username and allocate memory in the heap. However, when I run the code through gdb, name = "". What is causing this error?


Student question: the code is supposed to create a string name from the contents of username and allocate memory in the heap. However, when I run the code through gdb, name = "". What is causing this error? | Code context (simplify for kids): char *name = malloc(sizeof(char) * (strlen(username) + 1)); name[strlen(username)] = '\0';

Question: the code is supposed to create a string name from the contents of username and allocate memory in the heap. However, when I run the code through gdb, name = "". What is causing this error?


Student question: I want to save the contents of username in the heap using malloc. is this correct? | Code context (simplify for kids): client->username = malloc(sizeof(char) * (strlen(username) + 1)); client->username[strlen(username)] = '\0'; strncpy(client->username, username, strlen(name) + 1);

Question: I want to save the contents of username in the heap using malloc. is this correct?


Student question: I want to save the contents of username in the heap using malloc. is this correct? | Code context (simplify for kids): client->username = malloc(sizeof(char) * (strlen(username) + 1)); client->username[strlen(username)] = '\0'; strncpy(client->username, username, strlen(username) + 1);

Question: I want to save the contents of username in the heap using malloc. is this correct?


Student question: the code is supposed to take a string and tokenize it such that if the input string = "hello world here I am", cmd_argv[0] = "hello" cmd_argv[1] = "world" cmd_argv[2] = "here I am" and if input string = "hello world" cmd_argv[0] = "hello" cmd_argv[1] = "world" cmd_argv[2] = NULL but for the second example, I still get 3 values. What is the error? | Code context (simplify for kids): int cmd_argc = 0; char *next_token = strtok(cmd, DELIM); while (next_token != NULL && cmd_argc < 3) { cmd_argv[cmd_argc] = next_token; cmd_argc++; if (cmd_argc == 2) { char *rest = strtok(NULL, ""); cmd_argv[cmd_argc - 1] = strndup(cmd_argv[cmd_argc - 1], rest - cmd_argv[cmd_argc - 1] - 1); // ??? c

Question: the code is supposed to take a string and tokenize it such that if the input string = "hello world here I am", cmd_argv[0] = "hello" cmd_argv[1] = "world" cmd_argv[2] = "here I am" and if input string = "hello world" cmd_argv[0] = "hello" cmd_argv[1] = "world" cmd_argv[2] = NULL but for the second example, I still get 3 values. What is the error?


Student question: if I write "print var" and gdb outputs "0x0", is that the equivalent to var = NULL?

Question: if I write "print var" and gdb outputs "0x0", is that the equivalent to var = NULL?


Student question: why does this code give me a buffer overflow error? | Code context (simplify for kids): int len = 1; const User *current = curr; while (current != NULL) { len += strlen(current->name) + 2; current = current->next; } char *buf = malloc(sizeof(char) * len); int index = 0; int add = 0; while (curr != NULL) { add = snprintf(buf + index, len - index, "%s\r\n", curr->name); if (add >= len -

Question: why does this code give me a buffer overflow error?


Student question: if the date is jan. 1, 2021, what is the value of len? | Code context (simplify for kids): int len = strlen(asctime(localtime(post->date)))

Question: if the date is jan. 1, 2021, what is the value of len?


Task: The file /u/ajr/t contains zero or more integers, one per line. Write shell command to output the sum of all of these integers plus 10. (For example, if the file is empty, the output would be 10, or if it contains ‘‘2\n3\n’’ the output would be 15.)


Goal: traverse a linked list of User objects and print each User's name and a new line | Code context (simplify for kids): void list_users(const User *curr) { // traverse the linked list and print each name using printf User *node = curr; while (node != NULL) { printf("%s\n", node->name); node = node->next; } }


Goal: traverse a linked list of User objects and print each User's name and a new line | Code context (simplify for kids): void list_users(const User *curr) { // traverse the linked list and print each name using printf const User *node = curr; while (node != NULL) { printf("%s\n", node->name); node = node->next; } }


Goal: print an integer | Code context (simplify for kids): int i = 3; printf(i);


Student question: add action_pt to the end of the actions list of the current rule | Code context (simplify for kids): Action *last_act = curr_rule->actions; while (last_act->next_act != NULL) { last_act = last_act->next_act; } last_act->next_act = action_pt;

Question: add action_pt to the end of the actions list of the current rule


Student question: determine if a file exists | Code context (simplify for kids): int file_exists(char *filename) { FILE *f = fopen(filename, "r"); if (f != NULL) { fclose(f); return 1; } return 0; }

Question: determine if a file exists


Question: How does malloc work?


Goal: Prints: January February March Jan Feb Mar | Code context (simplify for kids): char **build_month_list() { char jan[] = "Januray"; char feb[] = "February"; char mar[] = "March"; char **array = malloc(sizeof(jan) * 3); array[0] = jan; array[1] = feb; array[2] = mar; return array; } int main() { // For part 3: Once you've implemented build_month_list, uncomment this code. char *


Student question: what kind of question do i ask you

Question: what kind of question do i ask you


Student question: how to initialize a string in c

Question: how to initialize a string in c


Student question: what type is result[0] in chat *result[2];

Question: what type is result[0] in chat *result[2];


Student question: how can i initialize a pointer to a struct

Question: how can i initialize a pointer to a struct


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 *); // testing to see if edits are working //jan 26 int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAG


Student question: how to define a string literal

Question: how to define a string literal


Code context (simplify for kids): // TODO: Implement populate_array /* * Convert a 9 digit int to a 9 element int array. */ int populate_array(int sin, int *sin_array) { int digits = 0; int num = sin; while(num != 0){ num = num / 10; digits += 1; } if(digits != 9){ return 1; } int position = 0; while(sin != 0){ sin_array[position] =


Code context (simplify for kids): // TODO: Implement populate_array /* * Convert a 9 digit int to a 9 element int array. */ int populate_array(int sin, int *sin_array) { int digits = 0; int position = 0; while(sin != 0){ sin_array[position] = sin % 10; digits += 1; position += 1; sin = sin / 10; } if (digits != 9){ return 1; } else{


Code context (simplify for kids): int populate_array(int sin, int *sin_array) { int digits = 0; int position = 0; while(sin != 0){ sin_array[position] = sin % 10; digits += 1; position += 1; sin = sin / 10; } if (digits != 9){ return 1; } else{ return 0; } } int check_sin(int *sin_array) { int sin_total = 0; for (int position = 0; p


Student question: how do I check if an element of a character array is 'a', 'b', or 'c'

Question: how do I check if an element of a character array is 'a', 'b', or 'c'


Student question: is this the right way to check if characters match | Code context (simplify for kids): if(required[i] == 'r' || required[i] == 'w' || required[i] == 'x'){ if (required[i] != permissions_field[i]){ return 1; } }

Question: is this the right way to check if characters match


Student question: is this checking the memory addresses | Code context (simplify for kids): if(required[i] == 'r' || required[i] == 'w' || required[i] == 'x'){ if (required[i] != permissions_field[i]){ return 1; } }

Question: is this checking the memory addresses


Student question: what operators are being used in the if statements | Code context (simplify for kids): if(required[i] == 'r' || required[i] == 'w' || required[i] == 'x'){ if (required[i] != permissions_field[i]){ return 1; } }

Question: what operators are being used in the if statements


Task: take two 9-element character arrays as arguments and returns an integer. (The prototype for this function is in the starter code.) The first array will represent the permission field of a file and the second will represent the permissions that are required. The function will return 0 if the file has all the required permissions and 1 otherwise. The arrays do not have to be identical for a 0 to be returned. For example, if the first array holds the characters rwxr-x--- and the second array holds


Code context (simplify for kids): if(required[i] == 'r' || required[i] == 'w' || required[i] == 'x'){ if (required[i] != permissions_field[i]){ return 1; } } // TODO: Implement a helper named check_permissions that matches the prototype below. //int check_permissions(char *, char *); int check_permissions(char *permissions_field, ch


Task: // TODO: Process command line arguments. // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. //check to make sure it's a regular file and not directory //check size // check permisions (or vice versa)


Task: Process command line arguments. Call check_permissions as part of your solution to count the files to compute and print the correct value.


Task: assign the variable p to be the permissions of the ls-l output


Student question: how do I add together the two digits of an integer

Question: how do I add together the two digits of an integer


Code context (simplify for kids): /* * Convert a 9 digit int to a 9 element int array. */ int populate_array(int sin, int *sin_array) { int position = 8; while(sin != 0){ sin_array[position] = sin % 10; sin = sin / 10; position -= 1; } return 0; }


Goal: turn 9 digit integer into 9 digit array, in same order. return 1 if the integer is less than 100000000 | Code context (simplify for kids): /* * Convert a 9 digit int to a 9 element int array. */ int populate_array(int sin, int *sin_array) { int position = 8; while(sin != 0){ sin_array[position] = sin % 10; sin = sin / 10; position -= 1; } return 0; }


Task: get the sum of the two digits of an integer between 10 and 20


Goal: if int i is even, add sin_array[I] to sin_total if int i is ODD, add the digits of sin_array at the ith position to sin_total | Code context (simplify for kids): int check_sin(int *sin_array) { int sin_total = 0; for(int i = 8; i>=0; i--){ if(i % 2 == 0){ sin_total += sin_array[i]; } else{ if(sin_array[i] < 5){ sin_total += (sin_array[i] * 2); } else{ int temp1 = sin_array[i] % 2; int temp2 = sin_array[i] / 10; int add = temp1 + temp2; sin_total += add; // i


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


Goal: /* * Print the usernames of all users in the list starting at curr. * Names should be printed to standard output, one per line. */ | Code context (simplify for kids): void list_users(const User *curr) { // start at the curr user User *curr_user = (User *) curr; // keep going through the linked list till the end is reached while(curr_user != NULL){ // THIS LINE BELOW IS A PROBLEM! printf(stdout, "%s\n", curr_user->name); //print_user(curr); curr_user = curr_user->


Task: how do I print the contents of a file


Goal: print the pfp (profile pic) in the beginning of the code. open the file containing it and print its contents. | Code context (simplify for kids): /* * Print a user profile. * For an example of the required output format, see the example output * linked from the handout. * Return: * - 0 on success. * - 1 if the user is NULL. */ int print_user(const User *user) { // check that the user exists User *print_me = (User *) user; if (print_me == NULL


Goal: /* * From the list pointed to by *user_ptr_del, delete the user * with the given name. * Remove the deleted user from any lists of friends. * * Return: * - 0 on success. * - 1 if a user with this name does not exist. */ make sure there are no memory leaks | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // find the user with that username User *delete_me = find_user(name, *user_ptr_del); // if it does not exist, return 1 if (delete_me == NULL){ return 1; } // once established that the user that u wanna delete does indeed exist in the // list


Goal: free the posts of this user | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { // find the user with that username User *delete_me = find_user(name, *user_ptr_del); // if it does not exist, return 1 if (delete_me == NULL){ return 1; } // once established that the user that u wanna delete does indeed exist in the // list


Task: start from the first node of a linked list and free every node


Goal: new children should not create additional processes | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> /* * Modify the program so that new children do not create additional processes */ int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); f


Code context (simplify for kids): main : linked_list.o main.o gcc - Wall - g - std = gnu99 - o main linked_list.o main .o main.o : main.c linked_list.h gcc - Wall - g - std = gnu99 - c main .c linked_list.o : linked_list.c linked_list.h gcc - Wall - g - std = gnu99 - c linked_list.c #notice that this target has no dependencies clean


Task: write code to parse through the makefile and make a linked data structure


Student question: 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 "); struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); x += 2; fprintf(stderr, "outside %d", x); return 0; }

Question: 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 "); struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); x += 2; fprintf(stderr, "outside %d", x); return 0; }


Question: explain strtok to me


Task: turn an action line of a makefile into a char **args


Task: assign the args to the new action node


Task: write code to turn an action line of a makefile into an array of strings


Task: get the number of actions in an action line of a makefile using strtok


Code context (simplify for kids): char *args_to_string(char **args, char *buffer, int size) { buffer[0] = '\0'; int i = 0; while (args[i] != NULL) { strncat(buffer, args[i], size - strlen(buffer)); strncat(buffer, " ", size - strlen(buffer)); i++; } return buffer; }


Student question: what should the parameters of fgets be when reading through the file pointed to by a file pointer

Question: what should the parameters of fgets be when reading through the file pointed to by a file pointer


Task: get the number of actions in the action line of a makefile


Task: Intended Behavior: get the number of actions in the action line of a makefile without modifying the makefile AT ALL


Student question: what does (.text+0x1b): undefined reference to `main' mean

Question: what does (.text+0x1b): undefined reference to `main' mean


Student question: What is this code doing? | Code context (simplify for kids): ((var |= 1 <<(flag)))

Question: What is this code doing?


Code context (simplify for kids): ((var) & (1 << (flag)))


Code context (simplify for kids): char * (*x) (char *) = my_func;


Student question: why (*x)? | Code context (simplify for kids): char * (*x) (char *) = my_func;

Question: why (*x)?


Student question: how does scanf treat white spaces

Question: how does scanf treat white spaces


Goal: pointer arithmetic and then taking the address of result | Code context (simplify for kids): &((*argc)+1);


Code context (simplify for kids): &((*argc)+1);


Goal: does pointer arithmetic then takes address of result | Code context (simplify for kids): &((*argv)+1);


Student question: what does it mean when standard input is closed in c

Question: what does it mean when standard input is closed in c


Student question: how do you close standard input in c

Question: how do you close standard input in c


Student question: what does the function strtok do to the string it is called on

Question: what does the function strtok do to the string it is called on


Student question: what happens when there is no delimiter in the string strtok is called on

Question: what happens when there is no delimiter in the string strtok is called on


Student question: How do you open a file

Question: How do you open a file


Student question: what are the all the ways to compare strings

Question: what are the all the ways to compare strings


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

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


Student question: how do you add elements to a char array

Question: how do you add elements to a char array


Student question: how do you add elements to an array

Question: how do you add elements to an array


Student question: what library do you need for len()

Question: what library do you need for len()


Student question: how do you calculate the length of an array

Question: how do you calculate the length of an array


Student question: how do you calculate the number of initialized spots in an array

Question: how do you calculate the number of initialized spots in an array


Student question: How do you find the number of elements in an array

Question: How do you find the number of elements in an array


Student question: What are the initial values of the elements in 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 are the initial values of the elements in friends


Student question: What are the initial values of the elements in friends. | Code context (simplify for kids): int main() { char *friends[10]; return 0; }

Question: What are the initial values of the elements in friends.


Student question: What are the initial values of the elements in name | 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 are the initial values of the elements in name


Student question: Where are structs stored in memory

Question: Where are structs stored in memory


Student question: What are the initial values of global data

Question: What are the initial values of global data


Student question: What are the initial values of heap data

Question: What are the initial values of heap data


Student question: What are the initial values of the data in structs that are defined in header files

Question: What are the initial values of the data in structs that are defined in header files


Student question: explain and generate an example of printing the contents of a text file

Question: explain and generate an example of printing the contents of a text file


Student question: generate example code of the fgets function being used on a file

Question: generate example code of the fgets function being used on a file


Student question: What is the keyword that indicates that a word is a legal target but isn't an actual file?

Question: What is the keyword that indicates that a word is a legal target but isn't an actual file?


Student question: What is rm -f *.o print_ptree? | Code context (simplify for kids): FLAGS = -Wall -Werror -std=c99 DEPENDENCIES = ptree.h all: print_ptree print_ptree: print_ptree.o ptree.o gcc ${FLAGS} -o $@ $^ %.o: %.c ${DEPENDENCIES} gcc ${FLAGS} -c $< clean: rm -f *.o print_ptree

Question: What is rm -f *.o print_ptree?


Student question: What is print_ptree? | Code context (simplify for kids): FLAGS = -Wall -Werror -std=c99 DEPENDENCIES = ptree.h all: print_ptree print_ptree: print_ptree.o ptree.o gcc ${FLAGS} -o $@ $^ %.o: %.c ${DEPENDENCIES} gcc ${FLAGS} -c $< clean: rm -f *.o print_ptree

Question: What is print_ptree?


Student question: is print_ptree a dependency? | Code context (simplify for kids): FLAGS = -Wall -Werror -std=c99 DEPENDENCIES = ptree.h all: print_ptree print_ptree: print_ptree.o ptree.o gcc ${FLAGS} -o $@ $^ %.o: %.c ${DEPENDENCIES} gcc ${FLAGS} -c $< clean: rm -f *.o print_ptree

Question: is print_ptree a dependency?


Student question: is print_ptree a variable | Code context (simplify for kids): FLAGS = -Wall -Werror -std=c99 DEPENDENCIES = ptree.h all: print_ptree print_ptree: print_ptree.o ptree.o gcc ${FLAGS} -o $@ $^ %.o: %.c ${DEPENDENCIES} gcc ${FLAGS} -c $< clean: rm -f *.o print_ptree

Question: is print_ptree a variable


Student question: is print_ptree a variable | Code context (simplify for kids): FLAGS = -Wall -Werror -std=c99 DEPENDENCIES = ptree.h all: print_ptree print_ptree: print_ptree.o ptree.o gcc ${FLAGS} -o $@ $^ %.o: %.c ${DEPENDENCIES} gcc ${FLAGS} -c $< clean: rm -f *.o print_ptree

Question: is print_ptree a variable


Student question: is print_ptree a recipe | Code context (simplify for kids): FLAGS = -Wall -Werror -std=c99 DEPENDENCIES = ptree.h all: print_ptree print_ptree: print_ptree.o ptree.o gcc ${FLAGS} -o $@ $^ %.o: %.c ${DEPENDENCIES} gcc ${FLAGS} -c $< clean: rm -f *.o print_ptree

Question: is print_ptree a recipe


Student question: is print_ptree a rule | Code context (simplify for kids): FLAGS = -Wall -Werror -std=c99 DEPENDENCIES = ptree.h all: print_ptree print_ptree: print_ptree.o ptree.o gcc ${FLAGS} -o $@ $^ %.o: %.c ${DEPENDENCIES} gcc ${FLAGS} -c $< clean: rm -f *.o print_ptree

Question: is print_ptree a rule


Student question: is print_ptree a prerequisite | Code context (simplify for kids): FLAGS = -Wall -Werror -std=c99 DEPENDENCIES = ptree.h all: print_ptree print_ptree: print_ptree.o ptree.o gcc ${FLAGS} -o $@ $^ %.o: %.c ${DEPENDENCIES} gcc ${FLAGS} -c $< clean: rm -f *.o print_ptree

Question: is print_ptree a prerequisite


Student question: is print_ptree a rule, target, dependency, variable, recipe, or prerequisite? | Code context (simplify for kids): FLAGS = -Wall -Werror -std=c99 DEPENDENCIES = ptree.h all: print_ptree print_ptree: print_ptree.o ptree.o gcc ${FLAGS} -o $@ $^ %.o: %.c ${DEPENDENCIES} gcc ${FLAGS} -c $< clean: rm -f *.o print_ptree

Question: is print_ptree a rule, target, dependency, variable, recipe, or prerequisite?


Code context (simplify for kids): typedef void(*SortFunc_t)(int *, int);


Student question: What is the return value of fgets?

Question: What is the return value of fgets?


Student question: explain the fread function

Question: explain the fread function


Student question: explain the fseek function

Question: explain the fseek function


Student question: What is the difference between text I/O and binary I/O

Question: What is the difference between text I/O and binary I/O


Question: What is size_t?


Student question: What does the od command do?

Question: What does the od command do?


Code context (simplify for kids): od --address-radix=x --format=c --format=dC <FILE>


Student question: generate a detailed documentation of `--format=dC` with usage examples and explanations

Question: generate a detailed documentation of `--format=dC` with usage examples and explanations


Student question: generate a detailed documentation of `--address-radix` with usage examples and explanations

Question: generate a detailed documentation of `--address-radix` with usage examples and explanations


Code context (simplify for kids): objdump --wide --sections <FILE>


Student question: What are the sections of an object file?

Question: What are the sections of an object file?


Code context (simplify for kids): objdump --wide --sections section=.rodata <FILE>


Code context (simplify for kids): objdump --full-contents section=.rodata <FILE>


Student question: What is the size of a long?

Question: What is the size of a long?


Student question: What is wrong with this line of code? | Code context (simplify for kids): fprintf(fp, 'A');

Question: What is wrong with this line of code?


Question: what does -lm do?


Code context (simplify for kids): gcc -Wall -g -std=gnu99 -o test_load_data dectree.o test_load_data.o -lm


Student question: What does the -lm do here? | Code context (simplify for kids): gcc -Wall -g -std=gnu99 -o test_load_data dectree.o test_load_data.o -lm

Question: What does the -lm do here?


Question: what does .PHONY do?


Student question: Give me an example of a call to the wait function

Question: Give me an example of a call to the wait function


Student question: generate example code for error checking with the fork function

Question: generate example code for error checking with the fork function


Student question: give me an example of a call to the strtok function

Question: give me an example of a call to the strtok function


Student question: give me an example of calling the execvp function

Question: give me an example of calling the execvp function


Student question: Is there a function to trim leading whitespace from a string?

Question: Is there a function to trim leading whitespace from a string?


Student question: What does the program print to stderr when it runs without interruption? | Code context (simplify for kids): int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); x += 2; fprintf(stderr, "outside %d", x); return 0; }

Question: What does the program print to stderr when it runs without interruption?


Student question: What does the program above (from part 1) print to stderr if the user presses Ctrl+C at the moment when the program is at position A? | Code context (simplify for kids): int x = 5; void handler(int sig) { x += 3; fprintf(stderr, "inside %d ", x); } int main() { fprintf(stderr, "start "); struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGINT, &act, NULL); x += 2; fprintf(stderr, "outside %d", x); return 0; }

Question: What does the program above (from part 1) print to stderr if the user presses Ctrl+C at the moment when the program is at position A?


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

Question: What does the program print to stderr if the user presses Ctrl+C at the moment when the program is at position B?


Student question: what is a "stubbed main file"?

Question: what is a "stubbed main file"?


Code context (simplify for kids): PORT = 51345 CFLAGS = DPORT = \$(PORT) - g - std = gnu99 - Wall - Werror


Student question: what does $< do in a makefile

Question: what does $< do in a makefile


Student question: what do $@ and $^ do in makefiles?

Question: what do $@ and $^ do in makefiles?


Student question: How do you use -D in the command line?

Question: How do you use -D in the command line?


Task: Give me examples of using -D from the command line.


Student question: does snprintf add a null terminator?

Question: does snprintf add a null terminator?


Student question: Can you have the same #include statement in two files that will be linked?

Question: Can you have the same #include statement in two files that will be linked?


Student question: How do I print cmd_argv[0][5] as a single character instead of an int? | Code context (simplify for kids): printf("cmd_argv[0][5]: %d\n", cmd_argv[0][5]);

Question: How do I print cmd_argv[0][5] as a single character instead of an int?


Student question: what is the digit 108 as a char?

Question: what is the digit 108 as a char?


Student question: what is the integer representation of the character '\r'?

Question: what is the integer representation of the character '\r'?


Student question: what will strcmp return in this case? | Code context (simplify for kids): strcmp("Grace\r", "Grace")

Question: what will strcmp return in this case?


Student question: Is it possible for a program to only work as intended when it is run through the gdb debugger?

Question: Is it possible for a program to only work as intended when it is run through the gdb debugger?


Student question: what does the FD_CLR macro do?

Question: what does the FD_CLR macro do?


Student question: How do you use strncat to safely concatenate two strings?

Question: How do you use strncat to safely concatenate two strings?


Student question: can I use snprintf on initialized memory?

Question: can I use snprintf on initialized memory?


Student question: can I use snprintf on uninitialized memory?

Question: can I use snprintf on uninitialized memory?


Student question: does this Makefile have any redundancies? | Code context (simplify for kids): PORT = 51345 CFLAGS = -DPORT =\$(PORT) - g - std = gnu99 - Wall - Werror OFLAGS = -g - std = gnu99 - Wall - Werror all : friend_server friend_server : friend_server.o friend_socket.o friends.o partial_io.o clients.o gcc ${CFLAGS} - o $ @$ ^ friend_server.o : friend_server.c friend_socket.h friends.h

Question: does this Makefile have any redundancies?


Student question: can you run strlen() on an integer?

Question: can you run strlen() on an integer?


Student question: is / integer division?

Question: is / integer division?


Student question: is there a built in function to remove element at specific index of an array

Question: is there a built in function to remove element at specific index of an array


Student question: why does this for loop print new twice | Code context (simplify for kids): char line[31]; int in; char new[9]; for (int i = 1; i < 10; i++) { new[i-1] = line[i]; printf("%s\n", new); }

Question: why does this for loop print new twice


Student question: why does this for loop print new twice. | Code context (simplify for kids): char line[31]; int in; char new[9]; for (int i = 1; i < 10; i++) { new[i-1] = line[i]; } printf("%s\n", new);

Question: why does this for loop print new twice.


Student question: Why does this code print new twice. For example, output was "rwx-------rwx------" but expected output is rwx------- | Code context (simplify for kids): char line[31]; int in; char new[9]; for (int i = 1; i < 10; i++) { new[i-1] = line[i]; } printf("%s\n", new);

Question: Why does this code print new twice. For example, output was "rwx-------rwx------" but expected output is rwx-------


Goal: output is rwx-------rwx------, expected output is rwx------- | Code context (simplify for kids): char line[31]; int in; char new[9]; for (int i = 1; i < 10; i++) { new[i-1] = line[i]; } printf("%s\n", new);


Student question: The string new is not properly terminated with a null character. -> This is fixed by adding \0 to the end of the string. How would I do that?

Question: The string new is not properly terminated with a null character. -> This is fixed by adding \0 to the end of the string. How would I do that?


Goal: EXC_BAD_ACCESS (code=1, address=0x0) in line 5. | Code context (simplify for kids): int main(int argc, char** argv) { char line[11]; int size; int count = 0; int int_size = strtol(argv[1], NULL, 10); char new[10]; if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } else if (argc == 3) { // Skip first line scanf("%*s, %*d"); while


Student question: is there a contains function? like if array contains item boolean

Question: is there a contains function? like if array contains item boolean