Student question: assign the amount in rain_today to the space rainfall points to | Code context (simplify for kids): int main(int argc, char **argv) { float *rainfall; float rain_today; }

Question: assign the amount in rain_today to the space rainfall points to


Student question: why do I get error with new_post.author = author->name | Code context (simplify for kids): int make_post(const User *author, User *target, char *contents) { if (author == NULL || target == NULL) { return 2; } if (check_friends((User *)author, target) == 1) { return 1; } struct post new_post; new_post.author = author->name; new_post.contents = contents; time_t curtime; new_post.date = &cur

Question: why do I get error with new_post.author = author->name


Student question: how to fix error for new_post->author = author->name | Code context (simplify for kids): int make_post(const User *author, User *target, char *contents) { if (author == NULL || target == NULL) { return 2; } if (check_friends((User *)author, target) == 1) { return 1; } Post *new_post = malloc(sizeof(Post)); new_post->author = author->name; new_post->contents = contents; time_t curtime; n

Question: how to fix error for new_post->author = author->name


Student question: does this work | Code context (simplify for kids): int check_friends(User *user1, User *user2) { int friends = 1; for (int i = 0; i < MAX_FRIENDS; i++) { if (strcmp((user1->friends[i])->name, user2->name) == 0) { friends = 0; break; } } return friends; }

Question: does this work


Student question: why do I have unitialised values | Code context (simplify for kids): void delete_from_friends(User *user) { for (int i = 0; i < MAX_FRIENDS; i++) { if (user->friends[i] == NULL) {} else { for (int j = 0; j < MAX_FRIENDS; j++) { User *friends_friend = user->friends[i]->friends[j]; if (friends_friend == NULL) {} else if (strcmp(friends_friend->name, user->name) == 0) {

Question: why do I have unitialised values


Student question: why do i have an error with if (friends_friend == NULL) {} | Code context (simplify for kids): void delete_from_friends(User *user) { for (int i = 0; i < MAX_FRIENDS; i++) { if (user->friends[i] == NULL) {} else { for (int j = 0; j < MAX_FRIENDS; j++) { User *friends_friend = user->friends[i]->friends[j]; if (friends_friend == NULL) {} else if (strcmp(friends_friend->name, user->name) == 0) {

Question: why do i have an error with if (friends_friend == NULL) {}


Student question: Is there a segmentation fault in this | Code context (simplify for kids): Rule *parse_file(FILE *fp) { // Implement this function and remove the stubbed return statement below. Rule *first_rule_ptr = NULL; Rule *last_rule_ptr = NULL; char str[MAXLINE]; while (fgets(str, MAXLINE, fp) != NULL) { if (str[0] == ' ' || str[0] == '\t' || str[0] == '\n') {} else if (is_comment_o

Question: Is there a segmentation fault in this


Code context (simplify for kids): void fib(int **fib_sequence, int count){ *fib_sequence = malloc(sizeof(int)*count); if (count == 1) { *fib_sequence[0] = 0; } else { *fib_sequence[0] = 0; *fib_sequence[1] = 1; for (int i = 2; i < count; i++) { *fib_sequence[i] = *fib_sequence[i-2] + *fib_sequence[i-1]; } } }


Student question: why do I get a segmentation fault

Question: why do I get a segmentation fault


Goal: generate the first n values in the Fibonacci sequence | Code context (simplify for kids): void fib(int **fib_sequence, int count){ *fib_sequence = malloc(sizeof(int)*count); if (count == 1) { *fib_sequence[0] = 0; } else { *fib_sequence[0] = 0; *fib_sequence[1] = 1; for (int i = 2; i < count; i++) { *fib_sequence[i] = *fib_sequence[i-2] + *fib_sequence[i-1]; } } }


Goal: generate the first n values in the Fibonacci sequence | Code context (simplify for kids): void fib(int **fib_sequence, int count){ int *cur = *fib_sequence cur = malloc(sizeof(int)*count); if (count == 1) { cur[0] = 0; } else { cur[0] = 0; cur[1] = 1; for (int i = 2; i < count; i++) { cur[i] = cur[i-2] + cur[i-1]; } } }


Goal: generate the first n values in the Fibonacci sequence | Code context (simplify for kids): void fib(int **fib_sequence, int count){ int *cur = *fib_sequence cur = malloc(sizeof(int)*count); if (count == 1) { *cur[0] = 0; } else { *cur[0] = 0; *cur[1] = 1; for (int i = 2; i < count; i++) { *cur[i] = *cur[i-2] + *cur[i-1]; } } }


Goal: generate the first n values in the Fibonacci sequence | Code context (simplify for kids): void fib(int **fib_sequence, int count){ int *cur = *fib_sequence cur = malloc(sizeof(int)*count); if (count == 1) { cur[0] = 0; } else { cur[0] = 0; cur[1] = 1; for (int i = 2; i < count; i++) { cur[i] = *cur[i-2] + *cur[i-1]; } } }


Goal: generate the first n values in the Fibonacci sequence | Code context (simplify for kids): void fib(int **fib_sequence, int count){ int *cur = *fib_sequence *cur = malloc(sizeof(int)*count); if (count == 1) { cur[0] = 0; } else { cur[0] = 0; cur[1] = 1; for (int i = 2; i < count; i++) { cur[i] = cur[i-2] + cur[i-1]; } } }


Goal: generate the first n values in the Fibonacci sequence | Code context (simplify for kids): void fib(int **fib_sequence, int count){ int *cur = **fib_sequence cur = malloc(sizeof(int)*count); if (count == 1) { cur[0] = 0; } else { cur[0] = 0; cur[1] = 1; for (int i = 2; i < count; i++) { cur[i] = cur[i-2] + cur[i-1]; } } }


Goal: It takes an integer and an integer array as its arguments, and returns an integer. This function's job is to populate the given integer array so that it contains the 9 digits of the given integer, in the same order as in the integer. | Code context (simplify for kids): int populate_array(int sin, int *sin_array) { for (int i = 8; i >= 0; i--){ sin_array[i] = sin % 10; sin = sin / 10; } if (sin != 0) { return 1; } else { return 0; } }


Goal: It takes an integer and an integer array as its arguments, and returns an integer. This function's job is to populate the given integer array so that it contains the 9 digits of the given integer, in the same order as in the integer. | Code context (simplify for kids): int populate_array(int sin, int *sin_array) { for (int i = 8; i >= 0; i--){ sin_array[i] = sin % 10; sin = sin / 10; } if (sin == 0) { return 0; } else { return 1; } }


Goal: it takes an 9 element integer array representing a candidate SIN number. It returns 0 if the number given is a valid Canadian SIN number, and 1 otherwise. | Code context (simplify for kids): int check_sin(int *sin_array) { int sin_total = 0; for (int i = 0; i < 9; i++){ if (i % 2 == 0){ int result = sin_array[i] * 2; //multiplies every second digit by 2 if (result >= 10) { sin_total += 1 + (result % 10); } else { sin_total += result; } } else { sin_total += sin_array[i]; } } if (sin_tot


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


Code context (simplify for kids): void list_users(const User *curr) { User *curr_user = (User *) curr; while (curr_user != NULL) { printf("%s\n", curr_user->name); curr_user = curr_user->next; } }


Student question: how to determine the number of elements in an array

Question: how to determine the number of elements in an array


Student question: Do we have to assign values to all attributes of a struct when creating a new instance of it

Question: Do we have to assign values to all attributes of a struct when creating a new instance of it


Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { int null_count = 0; for (int i = 0; i < capacity; i++) { if (src[i] == '\0') { // When src is less than or equal to capacity to be copied null_count += (capacity - i); break; } } if (null_count != 0) { for (int j = 0; j < capacity - null_count;


Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { for (int i = 0; i < capacity && src[i] != '\0'; i++) { dest[i] = src[i]; for ( ; i < capacity; i++) { dest[i] = '\0'; } } return dest; }


Student question: is the sizeof(int**) equal to sizeof(int*)

Question: is the sizeof(int**) equal to sizeof(int*)


Task: Get parent process to wait for all child process to complete


Student question: when a message with newlines is sent to a client from a server should the message end with one network newline or does the network newline replace all newline characters in the message

Question: when a message with newlines is sent to a client from a server should the message end with one network newline or does the network newline replace all newline characters in the message


Student question: When to use memset vs when to malloc

Question: When to use memset vs when to malloc


Student question: how to copy a char array to a char pointer

Question: how to copy a char array to a char pointer


Question: how to use select


Student question: print list | Code context (simplify for kids): int *make_list() { int list[3] = {1, 2, 3}; return list; } int main() { int *l = make_list(); int i; for (i = 0; i < 3; i++) { printf("%d\n", l[i]); } return 0; }

Question: print list


Student question: does initializing a char array include the null terminator

Question: does initializing a char array include the null terminator


Student question: store literal dynamically | Code context (simplify for kids): char *word = malloc(6 * sizeof(char)); *word = "hello";

Question: store literal dynamically


Student question: can strcpy alter string literal

Question: can strcpy alter string literal


Student question: how to guarantee order of output for child processes when forking

Question: how to guarantee order of output for child processes when forking


Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> #include <unistd.h> int main(int argc, char **argv) { int ret; int sum = 0; int status; for (int i = 1; i < argc; i++) { ret = fork(); if (ret < 0) { perror("fork"); exit(1); } else if (ret == 0) { int len = strlen(argv


Question: what is dup2 used for


Student question: modify the program so that the new children do not create additional processes. Only the original parent calls fork. Keep the printf call for all processes. | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); for (int i = 0; i < iterations; i++) { int n = fork(); if (n < 0) { perror("fork");

Question: modify the program so that the new children do not create additional processes. Only the original parent calls fork. Keep the printf call for all processes.


Goal: modify the program so that the new children do not create additional processes. Only the original parent calls fork. Keep the printf call for all processes. | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); for (int i = 0; i < iterations; i++) { int n = fork(); if (n < 0) { perror("fork");


Student question: modify the program so that the new children do not create additional processes. Only the original parent calls fork ITERATIONS times. Keep the printf call for all processes. | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); for (int i = 0; i < iterations; i++) { int n = fork(); if (n < 0) { perror("fork");

Question: modify the program so that the new children do not create additional processes. Only the original parent calls fork ITERATIONS times. Keep the printf call for all processes.


Student question: how to fork children processes in parallel and make the parent wait for all the childern

Question: how to fork children processes in parallel and make the parent wait for all the childern


Task: fork 5 child proccess in parallel and make the parent process wait until all child processes have terminated


Student question: how to fork childern sequentially and not in parallel

Question: how to fork childern sequentially and not in parallel


Student question: execvp: No such file or directory why am i getting this error

Question: execvp: No such file or directory why am i getting this error


Student question: Why does this compiling and executing this result in a segmentation fault? | Code context (simplify for kids): int main(int argc, char **argv) { // TODO: Verify that command line arguments are valid. if (argc != 2) { return 2; //returning with code 2 } // TODO: Parse arguments and then call the two helpers in sin_helpers.c // to verify the SIN given as a command line argument. int sin_number = strtol(argv[1]

Question: Why does this compiling and executing this result in a segmentation fault?


Student question: Does calling this function with appropriate parameters result in a segmentation fault? | Code context (simplify for kids): int populate_array(int sin, int *sin_array) { //setting up dummy variables to test whether sin is a 9 digit in int dummy = sin; int count = 0; while (dummy != 0) { dummy = dummy / 10; count = count + 1; } if (count != 9) { //10 didn't divide into sin exactly 9 times, thus the number is not a 9 digit

Question: Does calling this function with appropriate parameters result in a segmentation fault?


Student question: Will executing main result in a segmentation fault? | Code context (simplify for kids): #include <stdio.h> int check_sin(int *sin_array) { if (sin_array[0] == 0) { //assignment simplification: if it starts with 0 its invalid return 0; } else { int result[9]; int sum = 0; for (int i = 0; i < 9; i++) { if (i % 2 == 0) { //even indices get multiplied by 1 result[i] = sin_array[i]; //the r

Question: Will executing main result in a segmentation fault?


Student question: Does executing main result in a segmentation fault? | Code context (simplify for kids): #include <stdio.h> int populate_array(int sin, int *sin_array) { //setting up dummy variables to test whether sin is a 9 digit in int dummy = sin; int count = 0; while (dummy != 0) { dummy = dummy / 10; count = count + 1; } if (count != 9) { //10 didn't divide into sin exactly 9 times, thus the numb

Question: Does executing main result in a segmentation fault?


Student question: Does executing this code result in a segmentation fault? | Code context (simplify for kids): #include <stdio.h> int populate_array(int sin, int *sin_array) { //setting up dummy variables to test whether sin is a 9 digit in int dummy = sin; int count = 0; while (dummy != 0) { dummy = dummy / 10; count = count + 1; } if (count != 9) { //10 didn't divide into sin exactly 9 times, thus the numb

Question: Does executing this code result in a segmentation fault?


Student question: Does executing this code result in a segmentation fault? | Code context (simplify for kids): #include <stdio.h> int populate_array(int sin, int *sin_array) { //setting up dummy variables to test whether sin is a 9 digit in int dummy = sin; int count = 0; while (dummy != 0) { dummy = dummy / 10; count = count + 1; } if (count != 9) { //10 didn't divide into sin exactly 9 times, thus the numb

Question: Does executing this code result in a segmentation fault?


Student question: Why does executing this produce a segmentation fault? | Code context (simplify for kids): #include <stdio.h> int populate_array(int sin, int *sin_array) { //setting up dummy variables to test whether sin is a 9 digit in int dummy = sin; int count = 0; while (dummy != 0) { dummy = dummy / 10; count = count + 1; } if (count != 9) { //10 didn't divide into sin exactly 9 times, thus the numb

Question: Why does executing this produce a segmentation fault?


Student question: Why does running this produce a segmentation fault? | Code context (simplify for kids): #include <stdio.h> int check_sin(int *sin_array) { if (sin_array[0] == 0) { //assignment simplification: if it starts with 0 its invalid return 0; } else { int result[9]; int sum = 0; for (int i = 0; i < 9; i++) { if (i % 2 == 0) { //even indices get multiplied by 1 result[i] = sin_array[i]; //the r

Question: Why does running this produce a segmentation fault?


Goal: Outputs 1 | Code context (simplify for kids): #include <stdio.h> int check_sin(int *sin_array) { if (sin_array[0] == 0) { //assignment simplification: if it starts with 0 its invalid return 0; } else { int result[9]; int sum = 0; for (int i = 0; i < 9; i++) { if (i % 2 == 0) { //even indices get multiplied by 1 result[i] = sin_array[i]; //the r


Student question: Why does running this result in a segmentation fault? | Code context (simplify for kids): #include <stdio.h> int check_sin(int *sin_array) { if (sin_array[0] == 0) { //assignment simplification: if it starts with 0 its invalid return 1; } else { int result[9]; int sum = 0; for (int i = 0; i < 9; i++) { if (i % 2 == 0) { //even indices get multiplied by 1 result[i] = sin_array[i]; //the r

Question: Why does running this result in a segmentation fault?


Student question: Would the lines of code compile and execute without error always? | Code context (simplify for kids): int x; int *p = &x; printf("%d\n", *p);

Question: Would the lines of code compile and execute without error always?


Student question: Would the code compile and execute without error all the time? | Code context (simplify for kids): char arr[11] = "Basket"; strcat(arr, "ball"); printf("%s\n", arr);

Question: Would the code compile and execute without error all the time?


Student question: Would this code always compile and execute without error? | Code context (simplify for kids): char str[] = "CSC209"; char *s = "CSC209S"; s[6] = '\0'; printf("%d\n", strcmp(str, s));

Question: Would this code always compile and execute without error?


Student question: Does this code always compile and run without error | Code context (simplify for kids): char *get_extension(char •str) { char ext[4]; char *p; if ((p = strchr(str, '.')) != NULL) { strncpy(ext, p, 4); ext[3] = '\0'; return ext; } else { return NULL; } } printf("%s\n", get_extension("run.c"));

Question: Does this code always compile and run without error


Student question: Does running this code cause any errors such as segmentation fault | Code context (simplify for kids): char *get_extension(char *str) { char ext[4]; char *p; if ((p = strchr(str, '.')) != NULL) { strncpy(ext, p, 4); ext[3] = '\0'; return ext; } else { return NULL; } } printf("%s\n", get_extension("run.c"));

Question: Does running this code cause any errors such as segmentation fault


Student question: Why am I having a memory leakage from this? | 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; int print_user(const User *user) { if (user == NULL) { return 1; } else { // Prints the profil

Question: Why am I having a memory leakage from this?


Student question: Why am I having a memory leakage? It seems like the pic is being closed by fclose(pic); | 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; int print_user(const User *user) { if (user == NULL) { return 1; } else { // Prints the profil

Question: Why am I having a memory leakage? It seems like the pic is being closed by fclose(pic);


Task: /* Write the copy function to perform exactly as strncpy does, with one exception: your copy function will guarantee that dest is always null-terminated. Capacity is expected to be the number of bytes of memory allocated to dest. You shoud read the man page to learn how strncpy works. NOTE: You must write this function without using any string functions. The only function that should depend on string.h is memset. */


Code context (simplify for kids): #include <stdio.h> #define SIZE 4 #define OVERFLOW 4 int main() { int index = 0; int i; int before[SIZE] = {10, 10, 10, 10}; int a[SIZE] = {0, 0, 0, 0}; int after[SIZE] = {10, 10, 10, 10}; printf("Address of the variables:\n"); for (index = 0; index < SIZE; index++) { printf("%lx -> &after[%d]\n", (


Goal: Building a dynamic array containing the first n elements of the Fibonacci sequence | Code context (simplify for kids): void fib(int **fib_sequence, int count){ *fib_sequence = malloc(sizeof(int) * count); if (count >= 1){ (*fib_sequence)[0] = 0; } if (count >= 2){ (*fib_sequence)[1] = 1; } if (count >= 3){ for (int i = 2; i < count; i++){ (*fib_sequence)[i] = (*fib_sequence)[i-2] + (*fib_sequence)[i-1]; } } } int ma


Goal: /* * Convert a 9 digit int to a 9 element int array. */ | Code context (simplify for kids): int populate_array(int sin, int *sin_array) { int temp = sin; int size = 0; while (temp != 0){ temp /= 10; size ++; } if (size != 9) { return 1; } else { for (int i = size - 1; i >= 0; i--){ sin_array[i] = sin % 10; sin /= 10; } return 0; } }


Code context (simplify for kids): int populate_array(int sin, int *sin_array) { int temp = sin; int size = 0; while (temp != 0){ temp /= 10; size ++; } if (size != 9) { return 1; } else { for (int i = size - 1; i >= 0; i--){ sin_array[i] = sin % 10; sin /= 10; } return 0; } }


Goal: Open a file and print each line in the file to standard output | Code context (simplify for kids): FILE *file; char line[4096]; file = fopen(user->profile_pic, "r"); while (fgets(line, 4096, file) != NULL) { printf("%s", line); } fclose(file);


Goal: STORE the name of the file. Then you read the file and immediately print it back out. You can do this in pieces and never store the entire thing. If you think about it for a while, you will realize that you don't need to assume a maximum line length for using fgets. | Code context (simplify for kids): FILE *file; char line[4096]; char string[32]; strncpy(string, user->profile_pic, 32); file = fopen(string, "r"); while (fgets(line, 4096, file) != NULL) { printf("%s", line); } fclose(file);


Student question: You will need to use fork and execvp to the run the command specified by an action. Fortunately in Part 1, you already prepared the array of arguments to pass into execvp. The parent process should wait for each child to complete. If the child terminates with a non-zero exit status, the parent should also terminate with a non-zero exit status. This means that pmake will stop when it encounters an  | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> #include "pmake.h" void execute_action(Action *action) { printf("%s\n", *action->args); pid_t pid = fork(); if (pid == 0) { execvp(action->args[0], action

Question: You will need to use fork and execvp to the run the command specified by an action. Fortunately in Part 1, you already prepared the array of arguments to pass into execvp. The parent process should wait for each child to complete. If the child terminates with a non-zero exit status, the parent should also terminate with a non-zero exit status. This means that pmake will stop when it encounters an


Question: syntax for strtol


Question: how does scanf work?


Question: how does malloc work?


Question: what does strncpy do?


Question: How does wait work?


Student question: what are the attributes of the struct time_t

Question: what are the attributes of the struct time_t


Question: how does bind work


Task: how to find a character in a character array without a null terminator


Student question: print hello world | Code context (simplify for kids): print("Helloworld");

Question: print hello world


Student question: print Hello world | Code context (simplify for kids): printf("Hello world");

Question: print Hello world


Student question: print Hello world | Code context (simplify for kids): printf("Hello world\n");

Question: print Hello world


Question: what is valgrind?


Student question: what is the best way to debug c code?

Question: what is the best way to debug c code?


Student question: is a null pointer different from null?

Question: is a null pointer different from null?


Student question: how to count number of spaces in a string

Question: how to count number of spaces in a string


Question: what does getopt do?


Student question: what does the exec function do

Question: what does the exec function do


Question: how to use dup2


Question: how to use stat()


Student question: what is asprintf and how do i use it

Question: what is asprintf and how do i use it


Student question: what is line 3 doing | Code context (simplify for kids): FLAGS = -Wall - g - std = gnu99 all : classifier test_load_data classifier : dectree.o classifier.o gcc ${FLAGS} - o classifier dectree.o classifier.o - lm test_load_data : dectree.o test_load_data.o gcc ${FLAGS} - o test_load_data dectree.o test_load_data.o - lm classifier.o : classifier.c dectree.

Question: what is line 3 doing


Student question: in a makefile, are actions called if a target has no dependencies?

Question: in a makefile, are actions called if a target has no dependencies?


Question: what does wait() do?


Question: what does dup2() do?


Question: how to use pipe()


Student question: What value is returned by scanf when the input stream is closed?

Question: What value is returned by scanf when the input stream is closed?


Student question: What is the EOF symbol in C?

Question: What is the EOF symbol in C?


Student question: What is wrong with this code? | Code context (simplify for kids): #include <stdlib.h> #include <stdio.h> void fib(int **arr, int n) { *arr = malloc(sizeof(int) * n); *arr[0] = 0; int index = 1; if (n>=2) { *arr[1] = 1; index = 2; } while (index < n) { *arr[index] = *arr[index - 1] + *arr[index -2]; index ++; } } int main(int argc, char **argv) { /* do not change t

Question: What is wrong with this code?


Goal: build a dynamic array containing the first n fibonacci numbers, assuming that n is greater than or equal to 1. | Code context (simplify for kids): #include <stdlib.h> #include <stdio.h> void fib(int **arr, int n) { *arr = malloc(sizeof(int) * n); *arr[0] = 0; int index = 1; if (n>=2) { *arr[1] = 1; index = 2; } while (index < n) { *arr[index] = *arr[index - 1] + *arr[index -2]; index ++; } } int main(int argc, char **argv) { /* do not change t


Student question: how do i get the output of a shell command in my c program?

Question: how do i get the output of a shell command in my c program?


Student question: in the c programming language, how do i skip the rest of a line using scanf once I've gotten the data I wanted to use?

Question: in the c programming language, how do i skip the rest of a line using scanf once I've gotten the data I wanted to use?


Student question: how do i skip the rest of the line using scanf if there are spaces remaining?

Question: how do i skip the rest of the line using scanf if there are spaces remaining?


Student question: If I pipe the output of "ls -l" into a c program, how can I use scanf to get the size of each file?

Question: If I pipe the output of "ls -l" into a c program, how can I use scanf to get the size of each file?


Goal: I am piping the following output into this code: -rwx------ 1 reid staff 1734 Jun 22 14:52 prog -rw------- 1 reid staff 21510 Apr 6 12:10 tmp.txt -rwxr-xr-x 1 reid staff 8968 Feb 1 2013 xyz it should output: -rwx------1734 -rw------- 21510 -rwxr-xr-x 8968 | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } int size = strtol(argv[1], NULL, 10); int total = 0; int cur; char permissions[11]; scanf("%*s %*d"); while (scanf("%s %*d


Student question: I am piping the following output into this code: -rwx------ 1 reid staff 1734 Jun 22 14:52 prog -rw------- 1 reid staff 21510 Apr 6 12:10 tmp.txt -rwxr-xr-x 1 reid staff 8968 Feb 1 2013 xyz it should output: -rwx------1734 -rw------- 21510 -rwxr-xr-x 8968 | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } int size = strtol(argv[1], NULL, 10); //int total = 0; int cur; char permissions[11]; while (scanf("%s %*d %*s %*s %d %*s"

Question: I am piping the following output into this code: -rwx------ 1 reid staff 1734 Jun 22 14:52 prog -rw------- 1 reid staff 21510 Apr 6 12:10 tmp.txt -rwxr-xr-x 1 reid staff 8968 Feb 1 2013 xyz it should output: -rwx------1734 -rw------- 21510 -rwxr-xr-x 8968


Task: I am piping the following output into this code: -rwx------ 1 reid staff 1734 Jun 22 14:52 prog -rw------- 1 reid staff 21510 Apr 6 12:10 tmp.txt -rwxr-xr-x 1 reid staff 8968 Feb 1 2013 xyz it should use scanf to output: -rwx------1734 -rw------- 21510 -rwxr-xr-x 8968


Student question: after passing sin_array into the populate_array function, how do i access the modified array? | Code context (simplify for kids): #include <stdio.h> #include <stdlib.h> int populate_array(int, int *); int check_sin(int *); int main(int argc, char **argv) { // TODO: Verify that command line arguments are valid. if (argc != 2) { return 2; } // TODO: Parse arguments and then call the two helpers in sin_helpers.c // to verify the

Question: after passing sin_array into the populate_array function, how do i access the modified array?


Student question: How can I use time_t and ctime to get the current date/time as a string in the following format: "Friday Jan 27 23:01:00 2023"

Question: How can I use time_t and ctime to get the current date/time as a string in the following format: "Friday Jan 27 23:01:00 2023"


Student question: Why does this code not correctly set the friend_of_deleted->friends[j] element to NULL? I want to delete the element user_to_be_deleted from the array called friend_of_deleted->friends | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { User *user_to_be_deleted = find_user(name, *user_ptr_del); // Check existence if (user_to_be_deleted == NULL) { return 1; } // Delete from main user list if first if (*user_ptr_del == user_to_be_deleted) { *user_ptr_del = (*user_ptr_del)->next

Question: Why does this code not correctly set the friend_of_deleted->friends[j] element to NULL? I want to delete the element user_to_be_deleted from the array called friend_of_deleted->friends


Student question: Why does this code not correctly set the friend_of_deleted->friends[j] element to NULL? I want to delete the element user_to_be_deleted from the array called friend_of_deleted->friends | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { User *user_to_be_deleted = find_user(name, *user_ptr_del); // Check existence if (user_to_be_deleted == NULL) { return 1; } // Delete from main user list if first if (*user_ptr_del == user_to_be_deleted) { *user_ptr_del = (*user_ptr_del)->next

Question: Why does this code not correctly set the friend_of_deleted->friends[j] element to NULL? I want to delete the element user_to_be_deleted from the array called friend_of_deleted->friends


Goal: friend_of_deleted->friends contains the element user_to_be_deleted. This element should be deleted. | Code context (simplify for kids): int delete_user(const char *name, User **user_ptr_del) { User *user_to_be_deleted = find_user(name, *user_ptr_del); // Check existence if (user_to_be_deleted == NULL) { return 1; } // Delete from main user list if first if (*user_ptr_del == user_to_be_deleted) { *user_ptr_del = (*user_ptr_del)->next


Task: allocate memory to a node and then set it's value to "hello"


Student question: count the amount of words in string | Code context (simplify for kids): #include <stdio.h> #include <string.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> int count_words(char *sentence) { int count = 0; char* token = strtok(sentence, " "); while (token) { token++; token = strtok(NULL, " "); } return count; } int main() { int n; n = count_words("gcc -Wal

Question: count the amount of words in string


Student question: count the amount of words in string | Code context (simplify for kids): #include <stdio.h> #include <string.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> int count_words(char *sentence) { int count = 0; char* token = strtok(sentence, " "); while (token) { count++; token = strtok(NULL, " "); } return count; } int main() { int n; n = count_words("gcc -Wal

Question: count the amount of words in string


Task: function to count the number of words in a string


Student question: why does this return a bus error | Code context (simplify for kids): #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int count_words(char *sentence) { int count = 0; char *token = strtok(sentence, " "); while (token) { count++; printf("token: %s\n", token); token = strtok(NULL, " "); } return count; } int main() { ch

Question: why does this return a bus error


Student question: how are pointers used with structs?

Question: how are pointers used with structs?


Student question: could you explain what printf does?

Question: could you explain what printf does?


Code context (simplify for kids): for (int i = 0; i < 5; i++){ printf(i); }


Student question: can you declare two variables of the same type on one line?

Question: can you declare two variables of the same type on one line?


Student question: how do you find current time using time and ctime functions?

Question: how do you find current time using time and ctime functions?


Student question: what does fseek return?

Question: what does fseek return?


Student question: how would you free nodes in a linked list?

Question: how would you free nodes in a linked list?


Student question: How do you split a string on spaces?

Question: How do you split a string on spaces?


Student question: Can you write me a function that checks whether a string has any non-space characters?

Question: Can you write me a function that checks whether a string has any non-space characters?


Student question: how do I calculate how many space separated words make up a line of a file?

Question: how do I calculate how many space separated words make up a line of a file?


Student question: what is the return type of stat? and how do i call it to determine the last time a file was modified?

Question: what is the return type of stat? and how do i call it to determine the last time a file was modified?


Student question: how to generate a random number from 0-99 inclusive using random function?

Question: how to generate a random number from 0-99 inclusive using random function?


Code context (simplify for kids): for (;;) { ; }


Student question: how to set an alarm using setitimer and ITIMER_PROF?

Question: how to set an alarm using setitimer and ITIMER_PROF?


Code context (simplify for kids): struct itimerval new_time, old_time; new_time.it_interval.tv_usec = 0; new_time.it_interval.tv_sec = 5; new_time.it_value.tv_usec = 0; new_time.it_value.tv_sec = seconds; setitimer(ITIMER_PROF, &new_time, &old_time);


Code context (simplify for kids): struct itimerval new_time, old_time; new_time.it_interval.tv_usec = 0; new_time.it_interval.tv_sec = 0; new_time.it_value.tv_usec = 0; new_time.it_value.tv_sec = seconds; setitimer(ITIMER_PROF, &new_time, &old_time);


Student question: how do you make an alarm that will send the SIGPROF signal to a program while it's executing

Question: how do you make an alarm that will send the SIGPROF signal to a program while it's executing


Student question: I need this code to exit(0) when the timer sends a SIGPROF to the process | Code context (simplify for kids): /* The purpose of this program is to practice writing signal handling * functions and observing the behaviour of signals. */ #include <stdio.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> #include <sys/time.h> /* Message to print in the signal handling function. */ #define MESSAGE "%

Question: I need this code to exit(0) when the timer sends a SIGPROF to the process


Question: what is char**


Student question: how to dereference char**?

Question: how to dereference char**?


Code context (simplify for kids): print("Hello World")


Code context (simplify for kids): int main() { int i = 2; int j = 30; int a[4]; int *p; int *q; p = &i; j = *p; *p = 1; a[0] = 10; a[3] = 12; a[i] = 11; return 0; }


Student question: what will be the value of pA after execution? | Code context (simplify for kids): int A[4] = {5, 10, 15, 20}; int *pA = A[0]; pA += 1;

Question: what will be the value of pA after execution?


Student question: what will be the value of pA after execution? why? | Code context (simplify for kids): int A[4] = {5, 10, 15, 20}; int *pA = A[0]; pA += 1;

Question: what will be the value of pA after execution? why?


Student question: given an array of four random integers called arr, and a pointer to an integer called point, assign point to be the address of the last element in arr

Question: given an array of four random integers called arr, and a pointer to an integer called point, assign point to be the address of the last element in arr


Student question: what are strings in C?

Question: what are strings in C?


Student question: give an example of a linked list in C using structs

Question: give an example of a linked list in C using structs


Student question: in C, does scanf read until the newline?

Question: in C, does scanf read until the newline?


Student question: read past the first newline of scanf

Question: read past the first newline of scanf


Student question: generate a detailed documentation of `scanf("%*c%d", &number)` with usage examples and explanations

Question: generate a detailed documentation of `scanf("%*c%d", &number)` with usage examples and explanations


Student question: skip the first line of scanf

Question: skip the first line of scanf


Code context (simplify for kids): scanf("%c%s %*s %*s %*s %s", &type, perms, file_mem)


Student question: generate a detailed documentation of `%*[^\n]` with usage examples and explanations

Question: generate a detailed documentation of `%*[^\n]` with usage examples and explanations


Student question: what is the format specifier for a char

Question: what is the format specifier for a char


Student question: first character is empty when using the format specifier %*[^\n]

Question: first character is empty when using the format specifier %*[^\n]


Student question: discard newline in scanf

Question: discard newline in scanf


Student question: how to call a function located in file A from file B in the C programming language

Question: how to call a function located in file A from file B in the C programming language


Student question: will this code return 1? | Code context (simplify for kids): if (-1) { return 1; } return 0;

Question: will this code return 1?


Student question: %3s in scanf will only check for 3 characters?

Question: %3s in scanf will only check for 3 characters?


Student question: expected ‘char **’ but argument is of type ‘char (*)[50]’ how would i fix this issue?

Question: expected ‘char **’ but argument is of type ‘char (*)[50]’ how would i fix this issue?


Student question: why would this code have issues? | Code context (simplify for kids): void ask(char *arg[20]); int main() { char potato[20]; ask(&potato); return 0; }

Question: why would this code have issues?


Student question: is the null pointer always added to a string?

Question: is the null pointer always added to a string?


Student question: what would tar -czvf do?

Question: what would tar -czvf do?


Student question: what is $@ and $^ in bash scripting?

Question: what is $@ and $^ in bash scripting?


Student question: what is $@, $^, and $< in bash scripting?

Question: what is $@, $^, and $< in bash scripting?


Student question: what is % in bash scripting?

Question: what is % in bash scripting?


Student question: what is % in bash scripting for a makefile?

Question: what is % in bash scripting for a makefile?


Student question: pointer arithmetic with an array looks like?

Question: pointer arithmetic with an array looks like?


Student question: does sizeof function of an array return the length?

Question: does sizeof function of an array return the length?


Student question: let there be char **argv. when we do argv + 1, we are starting from the second element in the argv array of char pointers?

Question: let there be char **argv. when we do argv + 1, we are starting from the second element in the argv array of char pointers?


Student question: does line 2 give the number of elements in argv? | Code context (simplify for kids): char **argv; sizeof(argv) / sizeof(char**)

Question: does line 2 give the number of elements in argv?


Student question: Explain the strtok function in C. What is a token and a delimiter? How are they used?

Question: Explain the strtok function in C. What is a token and a delimiter? How are they used?


Student question: In C, if i call the error function with a string, it would print an error with that string? For example, if I had error("too many characters"); then the error would be "too many characters"?

Question: In C, if i call the error function with a string, it would print an error with that string? For example, if I had error("too many characters"); then the error would be "too many characters"?


Student question: On line 2, why does this not work? Why do we need to use strcpy? | Code context (simplify for kids): char s[] = "Hello"; s = "Bye";

Question: On line 2, why does this not work? Why do we need to use strcpy?


Student question: Does variable p get assigned to Smith after the program ends? | Code context (simplify for kids): char s[] = "Hello"; s = "Bye"; char *p = "Joe"; p = "Smith";

Question: Does variable p get assigned to Smith after the program ends?


Student question: Why does p get assigned to "Smith" but s does not get assigned to "Bye"? | Code context (simplify for kids): char s[] = "Hello"; s = "Bye"; char *p = "Joe"; p = "Smith";

Question: Why does p get assigned to "Smith" but s does not get assigned to "Bye"?


Student question: Why can you not reassign arrays in C? Is there a historical explanation for this?

Question: Why can you not reassign arrays in C? Is there a historical explanation for this?


Student question: Why can you not re-assign arrays?

Question: Why can you not re-assign arrays?


Student question: Will this work properly in C? | Code context (simplify for kids): char s[] = "Hello"; char s[] = "Goodbye";

Question: Will this work properly in C?


Student question: what is memcpy? how does it work? why?

Question: what is memcpy? how does it work? why?


Student question: What will be the behaviour of this program? Will the strncpy keep on copying all 10 bytes or will it know that s contains space for only 5 bytes and stop? | Code context (simplify for kids): char s[5]; strncpy(s, "hello world!!!!!!", 10);

Question: What will be the behaviour of this program? Will the strncpy keep on copying all 10 bytes or will it know that s contains space for only 5 bytes and stop?


Question: how to code in C


Question: how to input a string


Code context (simplify for kids): char phone[11]; int keypad; scanf("%s %d", &phone, &keypad);


Student question: How to compare two strings

Question: How to compare two strings


Goal: what malloc is incorrectly allocated | Code context (simplify for kids): int **result = malloc(sizeof(int*) * 2); result[0] = malloc(sizeof(int) * ((length + 1)/ 2)); result[1] = malloc(sizeof(int) * length / 2);


Student question: how to change a string array

Question: how to change a string array


Student question: how to mutate a char array.

Question: how to mutate a char array.


Goal: creating a copy of s char | Code context (simplify for kids): char tempString[strlen(s)] = s; strncpy(s, tempString, n); strlen(tempString);


Student question: how to add a item at the end of linked list

Question: how to add a item at the end of linked list


Goal: open the file and assign it to user profile pic | Code context (simplify for kids): int update_pic(User *user, const char *filename) { if (sizeof(filename) > 31) { return 2; } else if (fopen(filename, "r") == NULL) { return 1; } else { strncpy(user->profile_pic, filename, 32); }


Student question: how to compare two strings

Question: how to compare two strings


Student question: check if string array is empty

Question: check if string array is empty


Goal: author a struct should point to new post which is another struct | Code context (simplify for kids): (User *)author->first_post = &newPost;


Goal: author struct should point to newpost which is another struct | Code context (simplify for kids): author->first_post = &newPost;


Goal: author struct with property first_post should point to another struct newpost | Code context (simplify for kids): author->first_post = newPost;


Goal: author first post should point to new post | Code context (simplify for kids): Post *newPost = malloc(sizeof(Post)); author->first_post = newPost;


Goal: author first post should newPost | Code context (simplify for kids): Post *newPost = malloc(sizeof(Post)); author->first_post = newPost; strncpy(newPost->author, author->name, MAX_NAME); newPost->author[MAX_NAME-1] ='\0'; newPost->contents = contents; newPost->next = NULL;


Goal: insert before the first_post | Code context (simplify for kids): Post *prevPost = target->first_post; newPost->next = prevPost; target->first_post = newPost;


Goal: new post should be inserted infront of the list | Code context (simplify for kids): Post *newPost = malloc(sizeof(Post)); strncpy(newPost->author, author->name, MAX_NAME); newPost->author[MAX_NAME-1] ='\0'; newPost->contents = contents; if (target->first_post == NULL) { newPost->next = NULL; target->first_post = newPost; } else { newPost->next = target->first_post; target->first_po


Goal: storing current time as a date in newPost | Code context (simplify for kids): time_t current_time = time(NULL); newPost->date = &current_time;


Goal: remove curr from curr friend's list. | Code context (simplify for kids): for (int i = 0; i < MAX_FRIENDS; i++) { User *userFriend = find_user(curr->friends[i]->name, *user_ptr_del); if (userFriend != NULL) { for (int j = 0; j < MAX_FRIENDS; j++) { if (userFriend->friends[j] != NULL && strcmp(userFriend->friends[j]->name, curr->name) == 0) { userFriend->friends[j] = NULL;


Goal: copy char from src to dest | Code context (simplify for kids): char *copy(char *dest, const char *src, int capacity) { //dest = destination string // copy from source and dest int counter = 0; while (src[counter] != '\0' || counter < capacity) { dest[counter] = src[counter]; } dest[counter - 1] = '\0'; return dest; }


Goal: checking if current token is a colon | Code context (simplify for kids): if (strcmp(token, ":") == 0) { bool = 1; }


Student question: I am getting a segmentation fault when I run this on a bitmap display

Question: I am getting a segmentation fault when I run this on a bitmap display


Student question: I am getting a segmentation fault on this code

Question: I am getting a segmentation fault on this code


Student question: what does the mask do for sigaction?

Question: what does the mask do for sigaction?


Student question: what types of signals cannot be blocked?

Question: what types of signals cannot be blocked?


Code context (simplify for kids): struct itimerval timer_info; // Makes alarm happen only once timer_info.it_interval.tv_sec = 0; timer_info.it_interval.tv_usec = 0; // Sent it after s seconds timer_info.it_value.tv_sec = 1; timer_info.it_value.tv_usec = 0; if (setitimer(ITIMER_PROF, &timer_info, NULL) == -1) { perror("setitimer");


Goal: To print out the profile of the user | Code context (simplify for kids): int print_user(const User *user) { if (user == NULL) { return 1; } if (user->profile_pic[0] == '\0'){ FILE *fp; char line[100000]; fp = fopen(user->profile_pic, "r"); if (fp == NULL) { printf("Error opening file\n"); return 1; } while (fgets(line, 10000, fp) != NULL) { printf("%s", line); } fclose(f


Goal: Free the memory correctly | Code context (simplify for kids): int make_post(const User *author, User *target, char *contents) { if (author == NULL || target == NULL) { return 2; } bool is_friends = false; for (int i = 0; i < MAX_FRIENDS; i++) { if (target->friends[i] == author) { is_friends = true; break; } } if (!is_friends) { return 1; } Post *new_post = (Po


Student question: Part of a function called run_make which should check if the target in the make file exists nd is up to date. | Code context (simplify for kids): // check if the target exists and is up to date struct stat target_stat; struct stat dep_stat; if (stat(rule->target, &target_stat) == 0) { // target file exists int up_to_date = 1; for (Dependency *dep = rule->dependencies; dep != NULL; dep = dep->next_dep) { if (stat(dep->rule->target, &dep_stat)

Question: Part of a function called run_make which should check if the target in the make file exists nd is up to date.


Task: /* Evaluate the rule in rules corresponding to the given target. If target is NULL, evaluate the first rule instead. If pflag is 0, evaluate each dependency in sequence. If pflag is 1, then evaluate each dependency in parallel (by creating one new process per dependency). In this case, the parent process will wait until all child processes have terminated before checking dependency modified times to decide whether to execute the actions. */


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 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; }


Student question: If you type Ctl+C while this function is running then what happens? | 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: If you type Ctl+C while this function is running then what happens?


Student question: /* * Print the usernames of all users in the list starting at curr. * Names should be printed to standard output, one per line. * Return a dynamically allocated string containing the list of user names. */ | Code context (simplify for kids): char* list_users(const User *curr) { char* result = NULL; int len = 0; while (curr != NULL) { len += strlen(curr->name) + 1; // Add 1 for newline character curr = curr->next; } result = (char*) malloc(len + 1); // Add 1 for null terminator if (result == NULL) { perror("malloc"); exit(1); } char* ptr

Question: /* * Print the usernames of all users in the list starting at curr. * Names should be printed to standard output, one per line. * Return a dynamically allocated string containing the list of user names. */


Student question: /* * Print the usernames of all users in the list starting at curr. * Names should be printed to standard output, one per line. * Return a dynamically allocated string containing the list of user names. */ | Code context (simplify for kids): char* list_users(const User *curr) { char* result = NULL; int len = 0; while (curr != NULL) { len += strlen(curr->name) + 1; // Add 1 for newline character curr = curr->next; } result = (char*) malloc(len + 1); // Add 1 for null terminator if (result == NULL) { perror("malloc"); exit(1); } char* ptr

Question: /* * Print the usernames of all users in the list starting at curr. * Names should be printed to standard output, one per line. * Return a dynamically allocated string containing the list of user names. */


Student question: Will this give a segmentation fault?

Question: Will this give a segmentation fault?


Code context (simplify for kids): char* print_user(const User* user) { if (user == NULL) { return NULL; } int length = 0; length += snprintf(NULL, 0, "Name: %s\r\n\r\n", user->name); if (length < 0) { perror("snprintf"); exit(1); } char* output = malloc(length + 1); if (output == NULL) { perror("malloc"); exit(1); } length = strlen(


Question: fix my code


Goal: no segmentation fault | Code context (simplify for kids): int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } // TODO: Process command line arguments. if (!check_perm


Student question: do you have to initialize strings

Question: do you have to initialize strings


Student question: why can't i use scanf to write to a string if i did not initialize the string

Question: why can't i use scanf to write to a string if i did not initialize the string


Goal: I keep getting a segmentation error | Code context (simplify for kids): void fib(int** sequence, int n){ sequence = (int) malloc(sizeof(int) * n); (*sequence)[0] = 0; (*sequence)[1] = 1; for(int i = 2; i<n; i++){ (*sequence)[i] = (*sequence)[i-1] + (*sequence)[i-2]; } } int main(int argc, char **argv) { int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_


Code context (simplify for kids): void fib(int** sequence, int n){ sequence = (int) malloc(sizeof(int) * n); (*sequence)[0] = 0; (*sequence)[1] = 1; for(int i = 2; i<n; i++){ (*sequence)[i] = (*sequence)[i-1] + (*sequence)[i-2]; } } int main(int argc, char **argv) { int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_


Goal: Can you show me what is causing the segmentation errors | Code context (simplify for kids): void fib(int** sequence, int n){ sequence = (int) malloc(sizeof(int) * n); (*sequence)[0] = 0; (*sequence)[1] = 1; for(int i = 2; i<n; i++){ (*sequence)[i] = (*sequence)[i-1] + (*sequence)[i-2]; } } int main(int argc, char **argv) { int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_


Goal: supposed to take target and store the first amt characters in result. | Code context (simplify for kids): int truncate(char *target, int amt){ int leng = strlen(target); if (leng > amt){ return 0; } char result[45] = "abc" ; strncpy(result, target, amt); printf("This is the value of the truncated string: %s\n", result); return leng - amt ; }


Goal: I want to iterate through elements up until a point. Then if I reach that point, I want to shift each element from that point onwards to the left. | Code context (simplify for kids): for(int i=0; i<MAX_FRIENDS - 1; i++){ if(strcmp(curr->friends[i]->name, name) == 0){ //deleted user is in the list. curr->friends[MAX_FRIENDS - 1] = NULL; //Last element must be NULL after deletion. int j = i; for(int j; j < MAX_FRIENDS-1; j++){ //from i(index with deleted user), shift over every el


Code context (simplify for kids): for(int i=0; i<MAX_FRIENDS - 1; i++){ if(strcmp(curr->friends[i]->name, name) == 0){ //deleted user is in the list. curr->friends[MAX_FRIENDS - 1] = NULL; //Last element must be NULL after deletion. int j = i; for(int j; j < MAX_FRIENDS-1; j++){ //from i(index with deleted user), shift over every el


Goal: iterate through all of the User objects. For each user, it checks through the User's list of friends. | Code context (simplify for kids): User *current = *user_ptr_del; while(current != NULL){ printf("Now in %s\n", current->name); int i=0; for(i; i<MAX_FRIENDS - 1; i++){ if((current->friends[i] != NULL) && (strcmp(current->friends[i]->name, name) == 0)){ for(int i; i < MAX_FRIENDS-1; i++){ //from i(index with deleted user), shift over


Student question: how would i free the space that is allocated to post->contents | 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; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next;

Question: how would i free the space that is allocated to post->contents


Student question: how can I scan multiple lines with scanf

Question: how can I scan multiple lines with scanf


Student question: /bin/bash: line 1: [: too many arguments

Question: /bin/bash: line 1: [: too many arguments


Student question: how to read a multiline string using scan f until the end of the string?

Question: how to read a multiline string using scan f until the end of the string?


Question: what is a pointer


Student question: what is wrong with this test error? phone_loop_checker.py::TestPhoneLoop::test_valid fail 0 / 1 c_helper.py:125: in _t stdout, stderr, returncode = self._run_exec(args=args, input_=input_, timeout=timeout) c_helper.py:85: in _run_exec return _exec([os.path.join(".", self.executable_name)] + (args or []), **kwargs) c_helper.py:475: in _exec raise e from e c_helper.py:471: in _exec stdout, stderr =

Question: what is wrong with this test error? phone_loop_checker.py::TestPhoneLoop::test_valid fail 0 / 1 c_helper.py:125: in _t stdout, stderr, returncode = self._run_exec(args=args, input_=input_, timeout=timeout) c_helper.py:85: in _run_exec return _exec([os.path.join(".", self.executable_name)] + (args or []), **kwargs) c_helper.py:475: in _exec raise e from e c_helper.py:471: in _exec stdout, stderr =


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


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


Question: what does ls -s do


Student question: what does the number next to total in the output of ls -l mean

Question: what does the number next to total in the output of ls -l mean


Question: what is strtod in c


Student question: why is the first argument of argv indexed at 1

Question: why is the first argument of argv indexed at 1


Student question: when creating strings in C, do we need one extra element to hold any special characters?

Question: when creating strings in C, do we need one extra element to hold any special characters?


Student question: how do I take in a string as an argument

Question: how do I take in a string as an argument


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

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


Student question: how do I store a 5 length string from the command line argument

Question: how do I store a 5 length string from the command line argument


Student question: does c break conditionals early with &&

Question: does c break conditionals early with &&


Student question: how do I skip a line from the input with scanf

Question: how do I skip a line from the input with scanf


Student question: how do I split a string

Question: how do I split a string


Student question: string formatting doucmentation

Question: string formatting doucmentation


Student question: is this valid permission[10] = "---------\0";

Question: is this valid permission[10] = "---------\0";


Student question: print without special characters

Question: print without special characters


Student question: how do you properly compare strings in c

Question: how do you properly compare strings in c


Student question: how would I properly point to the parameters | Code context (simplify for kids): int check_permissions(char *current_perms, char *required_perms){ int i; for (i = 0; i < 9; i++) { if (strcmp(required_perms[i], "-") == 0 && strcmp(current_perms[i], "-") == 0) { return 1; } } return 0; }

Question: how would I properly point to the parameters


Student question: how do I compare a string literal with a element of a char array

Question: how do I compare a string literal with a element of a char array


Student question: what does this format mean | Code context (simplify for kids): %*[^\n]

Question: what does this format mean


Student question: can you explain %*[^\n] in detail

Question: can you explain %*[^\n] in detail


Student question: typecast bool to int in c

Question: typecast bool to int in c


Student question: how do I call helper functions from another file

Question: how do I call helper functions from another file


Student question: does c automatically convert integers to bools in conditionals

Question: does c automatically convert integers to bools in conditionals


Student question: provide documentation for strncmp

Question: provide documentation for strncmp


Student question: does argc include the name of the file

Question: does argc include the name of the file


Goal: it should compare if the 2 strings are equal | Code context (simplify for kids): if (strlen(argv[1]) == strlen(argv[2]) && strncmp(argv[1], argv[2], strlen(argv[1]) == 0)) { printf("Same\n"); }


Student question: difference between string literal and constant

Question: difference between string literal and constant


Student question: does adding a null terminator in the middle of a stack allocated string change the pointer of the stack

Question: does adding a null terminator in the middle of a stack allocated string change the pointer of the stack


Student question: how do you check if 2 strings are equal

Question: how do you check if 2 strings are equal


Code context (simplify for kids): char *a = argv[1]; char *b = argv[2]; if (*a == *b) { printf("Same\n"); }


Student question: how do I check for memory leaks

Question: how do I check for memory leaks


Student question: provide code for basic linked list traversal pattern

Question: provide code for basic linked list traversal pattern


Question: c do while


Student question: how do you vie stderror

Question: how do you vie stderror


Student question: waht does const do in parameter type

Question: waht does const do in parameter type


Question: how to use time()


Student question: how do you free a struct

Question: how do you free a struct


Student question: can I free a pointer but not the object it refers too if I have a copy of the pointer

Question: can I free a pointer but not the object it refers too if I have a copy of the pointer


Student question: does freeing a char array free the whole array

Question: does freeing a char array free the whole array


Student question: why does fork() not loop infinitely in a program

Question: why does fork() not loop infinitely in a program


Task: how do you allocate tokens from strtok into an array


Goal: In the space below, write a small program that allocates an array of integers in the main function and passes that array to a function called change. (You’ll also need to pass in the length of the array – why?) The function should do two things: • Add 10 to each element of the array. • Return the average of the new contents of the array. | Code context (simplify for kids): /****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *************************************************************************


Student question: How do I use fgets on an int

Question: How do I use fgets on an int


Student question: Your task is to write a C program called phone_loop.c. This program will again read from standard input using scanf and take no command-line arguments. Similar to phone.c, this program reads a 10-character string as the first input value but then it repeatedly reads integers until standard input is closed. (Hint: Use a while loop that checks the return value of scanf to accomplish this. Check the

Question: Your task is to write a C program called phone_loop.c. This program will again read from standard input using scanf and take no command-line arguments. Similar to phone.c, this program reads a 10-character string as the first input value but then it repeatedly reads integers until standard input is closed. (Hint: Use a while loop that checks the return value of scanf to accomplish this. Check the


Task: Your task is to write a C program called phone_loop.c. This program will again read from standard input using scanf and take no command-line arguments. Similar to phone.c, this program reads a 10-character string as the first input value but then it repeatedly reads integers until standard input is closed. (Hint: Use a while loop that checks the return value of scanf to accomplish this. Check the man page for scanf to determine the return value when the input stream is closed.) After each intege


Goal: Your task is to write a small C program called phone.c that uses scanf to read two values from standard input. The first is a 10 character string and the second is an integer. The program takes no command-line arguments. (You will write this program from scratch, so remember to add, commit, and push.) If the integer is -1, the program prints the full string to stdout. If the integer i is between 0 | Code context (simplify for kids): // Your task is to write a small C program called phone.c that uses scanf to read two values from standard input. #include <stdio.h> int main() { char phone[11]; printf("Type in a phone number:\n"); fgets(phone, 11, stdin); int number; printf("Type in a number:\n"); scanf("%d", &number); if (number


Goal: It is supposed to print the digit of the phone number corresponding to the variable number | Code context (simplify for kids): // Your task is to write a small C program called phone.c that uses scanf to read two values from standard input. #include <stdio.h> int main() { char phone[11]; printf("Type in a phone number:\n"); fgets(phone, 11, stdin); int number; printf("Type in a number:\n"); scanf("%d", &number); if (number


Goal: work | Code context (simplify for kids): int main(int argc, char** argv) { if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } // TODO: Process command line arguments. char* perms = argv[0]; int sizeLimit = stol(argv[1]) // TODO: Call check_permissions as part of your solution to count t


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


Goal: work | 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 *perm1, char *perm2){ for(int i = 0; i < 10; i++){ if (perm1[i] == '-'){ continue; } if (perm1[i] != perm2[i]){ return 0; } } return 1; }; int main(


Goal: work | 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 *perm1, char *perm2){ for(int i = 0; i < 10; i++){ if (perm2[i] == '-'){ continue; } if (perm1[i] != perm2[i]){ return 0; } } return 1; }; int main(


Student question: How do I use functions defined in another file?

Question: How do I use functions defined in another file?


Question: When do I use -> vs .


Student question: When do I use -> vs . ? Provide examples

Question: When do I use -> vs . ? Provide examples


Student question: What are default values for variables in C

Question: What are default values for variables in C


Student question: Does a program terminate when main returns? Justify your answer.

Question: Does a program terminate when main returns? Justify your answer.


Student question: Does this work | Code context (simplify for kids): int** code = {{0, 1}, {1, 2}}; int num = code[0][0]; int*** codeptr = &#

Question: Does this work


Student question: Why doesn't this work | Code context (simplify for kids): int** code = {{0, 1}, {1, 2}}; int num = code[0][0]; int*** codeptr = &#

Question: Why doesn't this work


Student question: Why is line 3 invalid? Explain using 3-5 sentences. | Code context (simplify for kids): int** code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int*** codeptr = &#

Question: Why is line 3 invalid? Explain using 3-5 sentences.


Student question: Does this work? Explain in 3-5 sentences. | Code context (simplify for kids): int** code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int** codeptr = &#

Question: Does this work? Explain in 3-5 sentences.


Student question: Does this work? | Code context (simplify for kids): int code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int** codeptr = &#

Question: Does this work?


Student question: Explain why this code does not work in 3-5 sentences. | Code context (simplify for kids): int code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int** codeptr = &#

Question: Explain why this code does not work in 3-5 sentences.


Student question: Does this work? | Code context (simplify for kids): int code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int** codeptr = &&#

Question: Does this work?


Student question: Can I ever have 2 or more & in a row?

Question: Can I ever have 2 or more & in a row?


Code context (simplify for kids): char** parseLine(char* line) { // Parse the line char** args = malloc(sizeof(char**)); char* arg = strtok(line, " "); // Parse the arguments and add them to args while (arg != NULL) { args = realloc(args, sizeof(char**) * (sizeof(args) + 1)); args[sizeof(args)] = arg; arg = strtok(NULL, " "); } retu


Student question: This should read the characters from line and generate an array of strings, one per argument | Code context (simplify for kids): char** parseLine(char* line) { // Parse the line char** args = malloc(sizeof(char**)); char* arg = strtok(line, " "); // Parse the arguments and add them to args while (arg != NULL) { args = realloc(args, sizeof(char**) * (sizeof(args) + 1)); args[sizeof(args)] = arg; arg = strtok(NULL, " "); } retu

Question: This should read the characters from line and generate an array of strings, one per argument


Student question: Does this work? | Code context (simplify for kids): cur_dep->rule = makeRule(); cur->next_rule = cur_dep->rule; cur = cur->next_rule;

Question: Does this work?


Student question: compile | Code context (simplify for kids): char* list_users(const User *curr) { const User *og_user = curr; char *user_list = NULL; int size = 11; while (curr != NULL) { size += strlen(curr->name) + 3; curr = curr->next; } user_list = malloc(sizeof(char)*size); if (user_list == NULL) { perror("malloc"); exit(1); } else { strcat(user_list, "U

Question: compile


Student question: how do i do stuff for sockets

Question: how do i do stuff for sockets


Student question: When I call gcc on a c file in the terminal, what file type is the output?

Question: When I call gcc on a c file in the terminal, what file type is the output?


Student question: what is a pointer variable?

Question: what is a pointer variable?


Student question: are there any bugs? | Code context (simplify for kids): int main() { char phone[11]; int i; scanf("%s", phone); scanf("%d", &i); if (i < -1 || i > 9) { printf("ERROR"); return 1; } else if (i == -1) { printf("%s", phone); } else { printf("%c", phone[i]); } return 0; }

Question: are there any bugs?


Student question: this is not working | Code context (simplify for kids): int **split_array(const int *s, int length) { int arr[2]; int numEven, numOdd; numOdd = length / 2; if (length % 2 == 0) { numEven = length / 2; } else { numEven = (length / 2) + 1; } arr[0] = malloc(sizeof(int) * numEven); arr[1] = malloc(sizeof(int) * numOdd); for (int i = 0; i < length; i = i + 2

Question: this is not working


Student question: not working | Code context (simplify for kids): int **split_array(const int *s, int length) { int **arr[2]; int numEven, numOdd; numOdd = length / 2; if (length % 2 == 0) { numEven = length / 2; } else { numEven = (length / 2) + 1; } arr[0] = malloc(sizeof(int) * numEven); arr[1] = malloc(sizeof(int) * numOdd); for (int i = 0; i < length; i = i +

Question: not working


Student question: not working | Code context (simplify for kids): int **split_array(const int *s, int length) { int *arr[2]; int numEven, numOdd; numOdd = length / 2; if (length % 2 == 0) { numEven = length / 2; } else { numEven = (length / 2) + 1; } arr[0] = malloc(sizeof(int) * numEven); arr[1] = malloc(sizeof(int) * numOdd); for (int i = 0; i < length; i = i +

Question: not working


Student question: not working | Code context (simplify for kids): int **split_array(const int *s, int length) { int *arr[2]; int numEven, numOdd; numOdd = length / 2; if (length % 2 == 0) { numEven = length / 2; } else { numEven = (length / 2) + 1; } arr[0] = malloc(sizeof(int) * numEven); arr[1] = malloc(sizeof(int) * numOdd); for (int i = 0; i < length; i = i +

Question: not working


Code context (simplify for kids): int **split_array(const int *s, int length) { int **arr = malloc(sizeof(int *) * 2); int numEven, numOdd; numOdd = length / 2; if (length % 2 == 0) { numEven = length / 2; } else { numEven = (length / 2) + 1; } arr[0] = malloc(sizeof(int) * numEven); arr[1] = malloc(sizeof(int) * numOdd); for (int i


Student question: give an example of a program that uses both scanf and command-line arguments

Question: give an example of a program that uses both scanf and command-line arguments


Student question: given an example of a program that uses scanf for several lines of input

Question: given an example of a program that uses scanf for several lines of input


Student question: give an example of a program that uses scanf

Question: give an example of a program that uses scanf


Student question: how many processes are forked? | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int original_process = getpid(); for (int i = 0; i < iterations; i++) { if (getpid()

Question: how many processes are forked?


Student question: describe the processes and their relationship to each other | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); int original_process = getpid(); for (int i = 0; i < iterations; i++) { if (getpid()

Question: describe the processes and their relationship to each other


Student question: describe the processes and their relationship to each other | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); for (int i = 0; i < iterations; i++) { int n = fork(); if (n < 0) { perror("fork");

Question: describe the processes and their relationship to each other


Question: how do i use dup2


Student question: how can i make the child process read two lines of pipe from the parent process in an execl call?

Question: how can i make the child process read two lines of pipe from the parent process in an execl call?


Student question: how can i use the execl call for standard input

Question: how can i use the execl call for standard input


Student question: i want to pass standard input from the parent process to a program being called in the child process using the execl call

Question: i want to pass standard input from the parent process to a program being called in the child process using the execl call


Student question: i have an execl call in my child process that reads from standard input. where do i close my file descriptors?

Question: i have an execl call in my child process that reads from standard input. where do i close my file descriptors?


Student question: how do i get a slice of an array in c

Question: how do i get a slice of an array in c


Student question: how do i convert a char array to a string array in c

Question: how do i convert a char array to a string array in c


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

Question: what is the difference between * and &?


Student question: how do i set a time_t?

Question: how do i set a time_t?


Code context (simplify for kids): #include <stdio.h> int main() { char c = 'b'; // declare and set variable c_ptr so that the code below prints 'b' // Submitted code below int *c_ptr = &c; // Submitted code above printf("%c", *c_ptr); return 0; }


Student question: I received an error when trying to run my executable on teach.cs, a shared Linux system. What is this error? How can it be fixed? /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found

Question: I received an error when trying to run my executable on teach.cs, a shared Linux system. What is this error? How can it be fixed? /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found


Code context (simplify for kids): int main(){ char phone[11]; int num; scanf("%s", phone); scanf("%d", &num); if (num == -1){ printf("%s\n", phone); return 0; } else if (num < -1 || num > 9){ printf("ERROR\n"); return 1; } else{ printf("%c\n", phone[num]); return 0; } }


Goal: This program will again read from standard input using scanf and take no command-line arguments. Similar to phone.c, this program reads a 10-character string as the first input value but then it repeatedly reads integers until standard input is closed. (Hint: Use a while loop that checks the return value of scanf to accomplish this. Check the man page for scanf to determine the return value when t | Code context (simplify for kids): int main(){ char phone[11]; int num; scanf("%s", phone); scanf("%d", &num); if (num == -1){ printf("%s\n", phone); return 0; } else if (num < -1 || num > 9){ printf("ERROR\n"); return 1; } else{ printf("%c\n", phone[num]); return 0; } }


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


Student question: what is static inline?

Question: what is static inline?


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


Student question: strtol does not set errno when it fails because it isn't a system call. why the above sentence wrong

Question: strtol does not set errno when it fails because it isn't a system call. why the above sentence wrong


Student question: strtol does not set errno when it fails because it isn't a system call.

Question: strtol does not set errno when it fails because it isn't a system call.


Student question: will system call set errno?

Question: will system call set errno?


Code context (simplify for kids): char name[5]; strncat(name, "Hi", 2);


Student question: How many processes are created, including the original parent, when the program is called with 2, 3, and 4 as arguments? n arguments? | Code context (simplify for kids): #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: forkloop <iterations>\n"); exit(1); } int iterations = strtol(argv[1], NULL, 10); for (int i = 0; i < iterations; i++) { int n = fork(); if (n < 0) { perror("fork");

Question: How many processes are created, including the original parent, when the program is called with 2, 3, and 4 as arguments? n arguments?


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 value stores in y at the end | Code context (simplify for kids): char *result[2]; x = result[0]; result[0] = "read only"; y = x[0];

Question: what value stores in y at the end


Student question: Is string literal differ than a char

Question: Is string literal differ than a char


Student question: When call fun('a') in main stack, will it allocate space for 'a'? | Code context (simplify for kids): int fun(char i) { ... } int main() { fun(’a’); }

Question: When call fun('a') in main stack, will it allocate space for 'a'?


Student question: what kind of error will the code has? what is the difference between run-time error and compile error? | Code context (simplify for kids): char *third = malloc(sizeof(char) * 10); third = "Wednesday"; third[0] = 'w';

Question: what kind of error will the code has? what is the difference between run-time error and compile error?


Student question: if argv[1] is zero, what kind of error will it incur | Code context (simplify for kids): int main(int argc, char **argv) { char *next = NULL; errno = 0; long longi = strtol(argv[1], &next, 0); int i = longi; printf("longi: %ld\n", longi); printf("i: %d\n", i); printf("next is |%s|\n", next); if (errno != 0) { perror("strtol"); } return 0; }

Question: if argv[1] is zero, what kind of error will it incur


Student question: what is the difference between execl and execvp

Question: what is the difference between execl and execvp


Question: what does dup2 do


Student question: what do signal mask do

Question: what do signal mask do


Question: what does accpet() do


Student question: what does sprintf() do

Question: what does sprintf() do


Student question: when will read() block

Question: when will read() block


Question: what does htons() do


Student question: what kind of error will occur is we do not double quote filename in shell programming?

Question: what kind of error will occur is we do not double quote filename in shell programming?


Student question: what are the attributes in struct called

Question: what are the attributes in struct called


Question: what does socket do


Question: what does port do


Question: what does listen() do


Question: what does dup2() do


Student question: why we use fprintf to output stderr

Question: why we use fprintf to output stderr


Student question: will main function always return int or can we set to be void

Question: will main function always return int or can we set to be void


Student question: does sizeof int different on different machine

Question: does sizeof int different on different machine


Student question: how to send SIGUSR1 signal to a process in command line

Question: how to send SIGUSR1 signal to a process in command line


Student question: If we want to modify permission of myscript.sh, when we use chmod, why we just write myscript rather than myscript.sh

Question: If we want to modify permission of myscript.sh, when we use chmod, why we just write myscript rather than myscript.sh


Student question: what does each of three permissions mean

Question: what does each of three permissions mean


Student question: what does /dev/null 2 /dev/null mean

Question: what does /dev/null 2 /dev/null mean


Student question: in shell programming, when to use test and when do not

Question: in shell programming, when to use test and when do not


Student question: can you show the process and the steps of creating and setting up a socket

Question: can you show the process and the steps of creating and setting up a socket


Student question: why the code below copies the fields of b into a. | Code context (simplify for kids): struct node a, b; a = b;

Question: why the code below copies the fields of b into a.


Student question: why this does not cause memory leak | Code context (simplify for kids): struct node { int val; struct node *next; }; void free_list(struct node *head) { while (head != NULL) { free(head); head = head->next; }

Question: why this does not cause memory leak


Student question: will exit after execl executed?

Question: will exit after execl executed?


Student question: what is the difference between execl, execlp, execv, execvp

Question: what is the difference between execl, execlp, execv, execvp


Student question: when calling select, what kind of fds will remain in the set

Question: when calling select, what kind of fds will remain in the set


Student question: what does this code mean | Code context (simplify for kids): list(product(self.NodeType, repeat = 2))

Question: what does this code mean


Code context (simplify for kids): char **last_names; last_names = malloc(sizeof(char*) * 4); last_names[0] = malloc(sizeof(char)* 20); last_names[1] = malloc(sizeof(char) * 20); last_names[2] = malloc(sizeof(char) * 20); last_names[3] = malloc(sizeof(char) * 20);


Question: explain **last_names


Student question: would this allocate the exact amount of memory of a float to allocated_amount | Code context (simplify for kids): allocated_amount = malloc(sizeof(float));

Question: would this allocate the exact amount of memory of a float to allocated_amount


Student question: how do you set the a variable x to the exact amount of space that should be allocated and pointed to by float *rainfall. | Code context (simplify for kids): float *rainfall = null;

Question: how do you set the a variable x to the exact amount of space that should be allocated and pointed to by float *rainfall.


Student question: will this program compile | Code context (simplify for kids): void main(int arc, char**argv) { char *size = argv[1]; if(argv == 3) { char*x = argv[2]; } }

Question: will this program compile


Student question: will this compile | Code context (simplify for kids): void main(int arc, char**argv) { char *size = argv[1]; if(argc == 3) { char*x = argv[2]; } }

Question: will this compile


Student question: will this compile | Code context (simplify for kids): int main(int argc, char**argv) { if (!(argc == 2 || argc ==3)) { fprintf(stderr, "x"); return 1; } char *size = argv[1]; if(argc == 3) { char*x = argv[2]; } return 0; }

Question: will this compile


Student question: How would i redirect information from a file as standard input using scanf?

Question: How would i redirect information from a file as standard input using scanf?


Student question: How would i redirect information from a file as standard input using scanf when i do not know the name of the file?

Question: How would i redirect information from a file as standard input using scanf when i do not know the name of the file?


Task: You should use scanf to read the input. Since your program reads from standard input, it would be possible to type all the input to your program from the keyboard. But typing in a listing that looks like the output from ls -l even once would be awful. Instead you could run ls -l and pipe its output to your program. Make sure you understand that last sentence and try it out. Even better, you should run ls -l and redirect its output to another file. Then edit that file to create different versions


Student question: how do i use scanf to read what i redirected to standard input

Question: how do i use scanf to read what i redirected to standard input


Student question: what will this code do

Question: what will this code do


Student question: what parameters should i be putting into full_array and result? | Code context (simplify for kids): int main(int argc, char **argv) { /* Replace the comments in the next two lines with the appropriate arguments. Do not add any additional lines of code to the main function or make other changes. */ int *full_array = build_array(argv[1], sizeof(argv[1]) / sizeof(argv[1][0])); int **result = split_ar

Question: what parameters should i be putting into full_array and result?


Student question: how can i fix this so my code compiles without error | Code context (simplify for kids): int main(int argc, char **argv) { /* Replace the comments in the next two lines with the appropriate arguments. Do not add any additional lines of code to the main function or make other changes. */ int *full_array = build_array(argv[1], argc - 1); int **result = split_array(full_array, sizeof(full_

Question: how can i fix this so my code compiles without error


Student question: how would i find the size of a pointer to an array

Question: how would i find the size of a pointer to an array


Student question: would this compile | Code context (simplify for kids): int main(int argc, char **argv) { /* Replace the comments in the next two lines with the appropriate arguments. Do not add any additional lines of code to the main function or make other changes. */ int *full_array = build_array(argv[1], argc - 1); int **result = split_array(full_array, sizeof(full_

Question: would this compile


Student question: how do i find the size of an array of int *

Question: how do i find the size of an array of int *


Goal: print out the array at odd and even indices | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int) * size); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; } int **split_array(const int *s, int length) { int **arrays = malloc(sizeof(int *) * 2); int *arr_even = malloc(sizeof(int) * ((length


Student question: what parameters should be passed to full_array and result? | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int) * size); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; } int **split_array(const int *s, int length) { int **arrays = malloc(sizeof(int *) * 2); int *arr_even = malloc(sizeof(int) * ((length

Question: what parameters should be passed to full_array and result?


Student question: what stops this from compiling | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int) * size); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; } int **split_array(const int *s, int length) { int **arrays = malloc(sizeof(int *) * 2); int *arr_even = malloc(sizeof(int) * ((length

Question: what stops this from compiling


Student question: what is the type of argv[1] | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int) * size); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; } int **split_array(const int *s, int length) { int **arrays = malloc(sizeof(int *) * 2); int *arr_even = malloc(sizeof(int) * ((length

Question: what is the type of argv[1]


Student question: will this compile | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int) * size); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; } int **split_array(const int *s, int length) { int **arrays = malloc(sizeof(int *) * 2); int *arr_even = malloc(sizeof(int) * ((length

Question: will this compile


Student question: will this compile | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int) * size); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; } int **split_array(const int *s, int length) { int **arrays = malloc(sizeof(int *) * 2); int *arr_even = malloc(sizeof(int) * ((length

Question: will this compile


Student question: how can i make sure that memory is allocated and free correctly | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int) * size); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; } int **split_array(const int *s, int length) { int **arrays = malloc(sizeof(int *) * 2); int *arr_even = malloc(sizeof(int) * ((length

Question: how can i make sure that memory is allocated and free correctly


Student question: how can i fix this code to ensure my memory is freed correctly | Code context (simplify for kids): int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int) * size); for (int i = 0; i < size; i++) { arr[i] = strtol(strs[i], NULL, 10); } return arr; } int **split_array(const int *s, int length) { int **arrays = malloc(sizeof(int *) * 2); int *arr_even = malloc(sizeof(int) * ((length

Question: how can i fix this code to ensure my memory is freed correctly


Student question: given a program where a pointer to an array of char pointers is passed as an argument, how can i print out the first 5 characters?

Question: given a program where a pointer to an array of char pointers is passed as an argument, how can i print out the first 5 characters?


Student question: how can i index input to get the first character | Code context (simplify for kids): int check_permissions(char *permission_field, char *required_permissions) { for (int i = 0; i < 9; i++) { if (required_permissions[i] == 'w' && permission_field[i] != 'w') { return 1; } else if (required_permissions[i] == 'r' && permission_field[i] != 'r') { return 1; } else if (required_permissions

Question: how can i index input to get the first character


Student question: how can i make permissions equal to the last 9 characters of input | Code context (simplify for kids): int check_permissions(char *permission_field, char *required_permissions) { for (int i = 0; i < 9; i++) { if (required_permissions[i] == 'w' && permission_field[i] != 'w') { return 1; } else if (required_permissions[i] == 'r' && permission_field[i] != 'r') { return 1; } else if (required_permissions

Question: how can i make permissions equal to the last 9 characters of input


Student question: why is it that when i index a pointer to a char array at index n, it gives me the same array starting from index n to the end?

Question: why is it that when i index a pointer to a char array at index n, it gives me the same array starting from index n to the end?


Goal: Modify s so it becomes the first n characters of s, and return how many letters in s were removed | Code context (simplify for kids): int truncate(char *s, int n) { char new_str[strlen(s)]; strncpy(new_str, s, n); new_str[strlen(s) - 1] = '\0'; s = new_str; return strlen(s) - n; }


Goal: /* * Read in the location of the pixel array, the image width, and the image * height in the given bitmap file. */ | Code context (simplify for kids): void read_bitmap_metadata(FILE *image, int *pixel_array_offset, int *width, int *height) { fseek(image,10, SEEK_SET); fread(&pixel_array_offset, sizeof(int), 1, image); fseek(image, 18, SEEK_SET); fread(&width, sizeof(int), 1, image); fseek(image, 22, SEEK_SET); fread(&height, sizeof(int), 1, image)


Student question: why do i get a segmentation fault when i try to print the contents of the file? how can i fix it? | Code context (simplify for kids): int print_user(const User *user) { if (user == NULL) { return 1; } FILE *file; file = fopen(user->profile_pic, "r"); char line[10]; while (fgets(line, 10, file) != NULL) { printf("%s", line); } fclose(file); printf("Name: %s\n", (char *)user->name); printf("------------------------------------------

Question: why do i get a segmentation fault when i try to print the contents of the file? how can i fix it?


Student question: what can i change to get rid of the makes pointer from integer without a cast error | Code context (simplify for kids): time_t curr_time = sizeof(time(NULL)); time(&curr_time); new_post->date = curr_time;

Question: what can i change to get rid of the makes pointer from integer without a cast error


Student question: what can i do to fix the makes pointer from integer without a cast error | Code context (simplify for kids): time_t curr_time = time(NULL); time(&curr_time); new_post->date = curr_time;

Question: what can i do to fix the makes pointer from integer without a cast error