user_id
stringlengths
24
24
time
stringlengths
24
24
feature_type
stringclasses
5 values
feature_version
stringclasses
2 values
input_question
stringlengths
1
1.24k
input_code
stringlengths
2
18.5k
input_intention
stringlengths
1
2.48k
input_task_description
stringlengths
18
3.32k
63c648395f004bf4898cfa95
2023-01-28T03:00:00.540Z
General Question
v1
write a scanf format string that only reads the second line of stdin
null
null
null
63c648395f004bf4898cfa95
2023-01-28T03:19:40.834Z
Question from Code
v1
does this compile? what does it do?
int num; scanf("%[^d]%d", &num);
null
null
63c648395f004bf4898cfa95
2023-01-28T03:20:18.581Z
General Question
v1
how do read until a character in scanf
null
null
null
63c648395f004bf4898cfa95
2023-01-28T03:26:30.695Z
General Question
v1
format specifier for int
null
null
null
63c648395f004bf4898cfa95
2023-01-28T03:27:42.392Z
General Question
v1
how to I read all consecutive integers from input?
null
null
null
63c648395f004bf4898cfa95
2023-01-28T03:33:17.658Z
General Question
v1
suppose stdin = "a b c 123 d" what would my scanf function call be to assign 123 to the variable num
null
null
null
63c648395f004bf4898cfa95
2023-01-28T04:42:46.028Z
General Question
v1
suppose we call scanf("%d", &num); on stdin "123". what will the value of num be?
null
null
null
63c648395f004bf4898cfa95
2023-01-28T15:02:11.740Z
Help Fix Code
v1
null
count_large.c:25:50: warning: format specifies type 'char *' but the argument has type 'int *' [-Wformat] done = scanf("%[^n] %*s %*s %*s %*s %d", &size); ~~~~ ^~~~~ %d count_large.c:25:46: warning: more '%' conversions than data arguments [-Wformat-insufficient-args] done = scanf("%[^n] %*s %*s %*s %*s %d", &size);
explain the warnings
null
63c648395f004bf4898cfa95
2023-01-28T15:02:40.595Z
General Question
v1
explain the warnings
null
null
null
63c648395f004bf4898cfa95
2023-01-28T15:04:49.350Z
General Question
v1
what is the format specifier to skip until the next newline
null
null
null
63c648395f004bf4898cfa95
2023-01-28T15:14:20.523Z
General Question
v1
write code to read a string from stdin using scanf and write it to a variable my_string
null
null
null
63c648395f004bf4898cfa95
2023-01-28T15:17:29.816Z
General Question
v1
give the string "-rw-r--r-- 4 joshualunger staff 763 27 Jan 17:01 Makefile" as standard input write a scanf function call to assign 763 to the variable "number"
null
null
null
63c648395f004bf4898cfa95
2023-01-28T17:07:56.859Z
Question from Code
v1
why would this return a segmentation fault?
char *word1 = NULL; char *word2 = NULL; char *word3 = NULL; char *word4 = NULL; int size; done = scanf("%s %s %s %s %d", word1, word2, word3, word4, &size); printf("%s\n%s\n%s\n%s\n%d", word1, word2, word3, word4, size);
null
null
63c648395f004bf4898cfa95
2023-01-28T17:08:49.256Z
Question from Code
v1
how do i allocated memory for the pointers so this is not a segmentation fault?
char *word1 = NULL; char *word2 = NULL; char *word3 = NULL; char *word4 = NULL; int size; done = scanf("%s %s %s %s %d", word1, word2, word3, word4, &size); printf("%s\n%s\n%s\n%s\n%d", word1, word2, word3, word4, size); char *word1 = NULL; char *word2 = NULL; char *word3 = NULL; char *word4 = NULL; int size; done = scanf("%s %s %s %s %d", word1, word2, word3, word4, &size); printf("%s\n%s\n%s\n%s\n%d", word1, word2, word3, word4, size);
null
null
63c648395f004bf4898cfa95
2023-01-28T17:09:50.728Z
General Question
v1
do we have to use allocated memory to assign strings with scanf?
null
null
null
63c648395f004bf4898cfa95
2023-01-28T17:11:29.835Z
Question from Code
v1
why do we need to allocate memory for the pointers in this code?
char *word1 = NULL; char *word2 = NULL; char *word3 = NULL; char *word4 = NULL; int size; done = scanf("%s %s %s %s %d", word1, word2, word3, word4, &size); printf("%s\n%s\n%s\n%s\n%d", word1, word2, word3, word4, size);
null
null
63c648395f004bf4898cfa95
2023-01-28T17:17:36.918Z
General Question
v1
do we always need to allocate memory when declaring a string if we don't want it to be a global variable in order to ensure there is not a segmentation fault?
null
null
null
63c648395f004bf4898cfa95
2023-01-28T17:17:55.102Z
General Question
v1
do we always need to allocate memory when declaring a string if we don't want it to be a global variable?
null
null
null
63c648395f004bf4898cfa95
2023-01-28T18:52:52.051Z
Help Fix Code
v1
null
int total; int done; done = scanf("%*s %d %*c", &total); printf("%d\n%d\n", total, done); int size = malloc(sizeof(int)); done = scanf("%*s %*s %*s %*s %d", size); printf("%d\n%d\n", size, done);
given the stdin "total 320 -rw-r--r-- 4 joshualunger staff 763 27 Jan 17:01 Makefile -rwxr-xr-x 1 joshualunger staff 33560 27 Jan 22:24 count_large " return 310\n1\n763\n1 to stdin
null
63c648395f004bf4898cfa95
2023-01-28T20:35:35.798Z
Question from Code
v1
suppose we pass "total 320 -rw-r--r-- 4 joshualunger staff 763 27 Jan 17:01 Makefile -rwxr-xr-x 1 joshualunger staff 33560 27 Jan 22:24 count_large " to stdin and run this code. Why do we get a segmentation fault?
int total; int done; done = scanf("%*s %d %*c", &total); printf("%d\n%d\n", total, done); int size = malloc(sizeof(int)); done = scanf("%*s %*s %*s %*s %d", &size); printf("%d\n%d\n", size, done); done = scanf("%[^\n] %*s %*s %*s %*s %d", &size); printf("%d\n%d\n", size, done);
null
null
63c648395f004bf4898cfa95
2023-01-28T20:36:24.666Z
Question from Code
v1
where does scanf write to memory it doesn't own?
int total; int done; done = scanf("%*s %d %*c", &total); printf("%d\n%d\n", total, done); int size = malloc(sizeof(int)); done = scanf("%*s %*s %*s %*s %d", &size); printf("%d\n%d\n", size, done); done = scanf("%[^\n] %*s %*s %*s %*s %d", &size); printf("%d\n%d\n", size, done);
null
null
63c648395f004bf4898cfa95
2023-01-28T21:04:15.561Z
Question from Code
v1
why does this give error: expected identifer?
int size; done = scanf("%*s %*s %*s %*s %d %*s %*s %*s %*s", &size); if (done == 1) && (size > max_size){ num_large += 1; } }
null
null
63c648395f004bf4898cfa95
2023-01-28T21:14:25.445Z
Question from Code
v1
why does this give a warning
strtol(argv, Null, 10);
null
null
63c648395f004bf4898cfa95
2023-01-28T21:14:51.322Z
Question from Code
v1
why does this give a warning about argv?
strtol(argv, NULL, 10);
null
null
63c648395f004bf4898cfa95
2023-01-28T21:17:37.777Z
Question from Code
v1
suppose we run this code with "345" as argv[1]. why does it print "3450"?
int max_size = strtol(argv[1], NULL, 10); printf("%d", max_size); int num_large = 0;
null
null
63c648395f004bf4898cfa95
2023-01-28T23:15:26.479Z
Question from Code
v1
why doesn't this compile
int main(int argc, char** argv){ if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } printf("line19\n"); // initialize program variables int max_size = (int)strtol(argv[1], NULL, 10); int num_large = 0; int num_large_permissions = 0; int total; int done; // initialize req_permissions char *req_permissions = NULL; if(argv[2] != NULL){ for (int i = 0; i < 9; i++){ req_permissions[i] = argv[2][i]; } } // discard total data done = scanf("%*s %d %*c", &total); printf("line38\n"); printf("done %d", done); // iterate over lines while (done == 1){ printf("initializing size, permissions); int size; char *permissions = NULL; printf("about to scan"); done = scanf("%*c %s %*s %*s %*s %d %*s %*s %*s %*s", permissions, &size); printf("while loop\n"); if ((done == 1) && (size > max_size)){ num_large += 1; if((argc == 2) && (check_permissions(req_permissions, permissions) == 0)){ num_large -= 1; } } } printf("%d", num_large); return 0; }
null
null
63c648395f004bf4898cfa95
2023-01-28T23:16:40.919Z
Question from Code
v1
why doesn't this compile?
#include <stdio.h> #include <stdlib.h> // check_permissions int check_permissions(char *req_permissions, char *permissions){ for(int i = 0; i < 9; i++){ if((req_permissions[i] != 13) && (permissions[i] != req_permissions[i])){return 0;} } return 1; } // main method int main(int argc, char** argv){ if (!(argc == 2 || argc == 3)) { fprintf(stderr, "USAGE: count_large size [permissions]\n"); return 1; } printf("line19\n"); // initialize program variables int max_size = (int)strtol(argv[1], NULL, 10); int num_large = 0; int num_large_permissions = 0; int total; int done; // initialize req_permissions char *req_permissions = NULL; if(argv[2] != NULL){ for (int i = 0; i < 9; i++){ req_permissions[i] = argv[2][i]; } } // discard total data done = scanf("%*s %d %*c", &total); printf("line38\n"); printf("done %d", done); // iterate over lines while (done == 1){ printf("initializing size, permissions); int size; char *permissions = NULL; printf("about to scan"); done = scanf("%*c %s %*s %*s %*s %d %*s %*s %*s %*s", permissions, &size); printf("while loop\n"); if ((done == 1) && (size > max_size)){ num_large += 1; if((argc == 2) && (check_permissions(req_permissions, permissions) == 0)){ num_large -= 1; } } } printf("%d", num_large); return 0; }
null
null
63c648395f004bf4898cfa95
2023-01-30T20:12:46.891Z
Question from Code
v1
don't lines 2 and 3 not actually change s1?
char s1[22] = "Cat got your tongue?"; char s2[2] = "\0"; strncat(s1, s2, 1); printf("%s", s1);
null
null
63c648395f004bf4898cfa95
2023-02-12T22:05:29.034Z
Help Fix Code
v1
null
if((User *new_user = malloc(sizeof(User))) == NULL){return 0;}
initialize a User struct on the heap and pass the address to new_user. If there is no memory available, return 0.
null
63c6483a5f004bf4898cfa9a
2023-04-25T19:55:34.222Z
General Question
v2
multiple process can use the same port to listen for connections
null
null
null
63c6483b5f004bf4898cfaa9
2023-01-27T05:21:08.693Z
Help Fix Code
v1
null
void fib(int **seq, int n){ int *sequence = malloc(sizeof(int*) * n); *seq = sequence; *seq[0] = 0; *seq[1] = 1; int i = 2; while (i<=n){ *seq[i] =*seq[i-2] + *seq[i-1]; } }
update seq
null
63c6483b5f004bf4898cfaa9
2023-01-30T23:04:54.140Z
Help Fix Code
v1
null
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. // int limit; limit = strtol(argv[1], NULL, 10); char *permission[9]; // scanf("%10s", permission); permission = &argv[2]; char* files; scanf("%32s", files); // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. int return_value = 0; scanf("%s", files); while (files[0] != 'E' ){ if (files[0] != 'd' ){ char *leftover; int size_file = strtol(files, &leftover, 10); char *file_permission[9]; file_permission = &files[1]; if (check_permissions(*file_permission,*permission) != 1 && size_file < limit ){ return_value ++; } } scanf("%s", files); } printf("%d", return_value); return 0; }
input permission given from command arguments
null
63c6483b5f004bf4898cfaa9
2023-01-30T23:09:35.285Z
Help Fix Code
v1
null
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. // int limit; limit = strtol(argv[1], NULL, 10); char *permission[9]; // scanf("%10s", permission); permission = argv[2]; char* files[32]; scanf("%32s", *files); // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. int return_value = 0; scanf("%s", *files); while (files[0] != 'E' ){ if (files[0] != 'd' ){ char *leftover; int size_file = strtol(files, &leftover, 10); char *file_permission[9]; file_permission = files[1]; if (check_permissions(*file_permission,*permission) != 1 && size_file < limit ){ return_value ++; } } scanf("%s", *files); } printf("%d", return_value); return 0; }
assign permission based on command line input
null
63c6483b5f004bf4898cfaa9
2023-03-17T21:36:10.663Z
General Question
v2
write to file integers 1 to 100 in binary form
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-17T21:58:37.521Z
General Question
v2
random(100)
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-17T22:04:56.298Z
General Question
v2
seek to a random location in the file
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-17T22:06:17.635Z
Help Write Code
v2
null
null
null
seek to a random location in the file
63c6483b5f004bf4898cfaa9
2023-03-17T22:07:26.850Z
General Question
v2
seek to a random location in the file
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-17T22:11:00.894Z
General Question
v2
seek to a random location in the file and print its value
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-17T22:12:50.637Z
General Question
v2
Now, use sigactionLinks to an external site. to add a signal handler to your program. Start with something simple that just prints a message to standard out and exits (with termination code 0) when it receives a SIGPROF. Then, to test it, run your program and use kill to send it a SIGPROF signal from the shell in another terminal window. (Check the man page for killLinks to an external site. to see how to get a listing of signals and their numbers.)
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-17T22:14:34.716Z
General Question
v2
SIGPROF() usage
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-17T22:17:11.823Z
General Question
v2
sigaction() usage
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-17T22:19:01.060Z
General Question
v2
Now, use sigactionLinks to an external site. to add a signal handler to your program. Start with something simple that just prints a message to standard out and exits (with termination code 0) when it receives a SIGPROF.
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-17T22:24:40.663Z
General Question
v2
set field sa_handler of sa to signal_handler
null
null
null
63c6483b5f004bf4898cfaa9
2023-03-31T21:03:42.603Z
Help Write Code
v2
null
null
null
test malloc fail or not
63c6483b5f004bf4898cfaa9
2023-03-31T21:16:28.573Z
Help Fix Code
v2
access the username attribute of users[fd] which is the fd th user in a list of sturcts
char* echo_msg = "%s:%s", users[fd].username, buf;
null
null
63c6483b5f004bf4898cfaa9
2023-03-31T21:22:18.503Z
Help Write Code
v2
null
null
null
concatenate username, and message with ":" in the middle and sent it through a socket
63c6483c5f004bf4898cfaae
2023-01-20T19:15:34.729Z
General Question
v1
how does scans() work?
null
null
null
63c6483c5f004bf4898cfaae
2023-01-20T19:16:36.094Z
General Question
v1
how could I end scanf() when it is at the end of the file?
null
null
null
63c6483c5f004bf4898cfaae
2023-01-20T19:18:15.782Z
Explain Code
v1
null
int main(int argc, char **argv) { // Read in the command-line arguments and convert the strings to doubles double principal = strtod(argv[1], NULL); double rate = strtod(argv[2], NULL); // Call invest to make you more money invest(&principal, rate); printf("%.2f\n", principal); return 0; }
null
null
63c6483c5f004bf4898cfaae
2023-01-26T20:07:37.861Z
Help Fix Code
v1
null
void fib(int **sequence, int n){ // allocate space int **sequence = malloc(sizeof(int *)); int sequence[0] = malloc(sizeof(int) * n); /* set the first two elements */ sequence[0][0] = 0; sequence[0][1] = 1; /* the rest of the sequence */ for (int i = 2; i < n; i++){ sequence[0][i] = sequence[0][i-2] + sequence[0][i-1]; } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
Define a function void fib(...) below. This function takes parameter n * and generates the first n values in the Fibonacci sequence. Recall that this * sequence is defined as: * 0, 1, 1, 2, 3, 5, ... , fib[n] = fib[n-2] + fib[n-1], ... * The values should be stored in a dynamically-allocated array composed of * exactly the correct number of integers. The values should be returned * through a pointer parameter passed in as the first argument. * * See the main function for an example call to fib. * Pay attention to the expected type of fib's parameters.
null
63c6483c5f004bf4898cfaae
2023-02-10T22:39:15.331Z
General Question
v1
how to check my code pointing to image files?
null
null
null
63c6483c5f004bf4898cfaae
2023-02-14T17:56:23.250Z
General Question
v1
How to cast a type to another in c?
null
null
null
63c6483c5f004bf4898cfaae
2023-02-14T18:47:22.919Z
General Question
v1
expected ‘const char * restrict’ but argument is of type ‘char’
null
null
null
63c6483c5f004bf4898cfaae
2023-02-14T18:51:23.722Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { // Check whether the given name could fit in the 'name' array if (strlen(name) + 1 >= MAX_NAME) { return 2; } // Check if the given name already exists in the list // Move to the next item in the linked list by 'next' while ((**user_ptr_add).next != NULL) { if ((**user_ptr_add).name == name) { return 1; } } // Insert the user if the given name is valid // Copy the name strncpy((**user_ptr_add).name, name, MAX_NAME - 1); // Initiate the other elements (**user_ptr_add).first_post = NULL; // For the linked list of friends set the first element to NULL *(**user_ptr_add).friends = NULL; (**user_ptr_add).next = NULL; // Return the code if successfully run return 0; }
create a user with type of struct User
null
63c6483c5f004bf4898cfaae
2023-03-03T20:33:14.828Z
General Question
v1
how to prevent a child process creating new processes
null
null
null
63c6483c5f004bf4898cfaae
2023-03-03T20:56:59.420Z
General Question
v1
how to use makefile to compile a specific file
null
null
null
63c6483c5f004bf4898cfaae
2023-03-03T22:16:19.669Z
General Question
v1
how to end a void function
null
null
null
63c6483c5f004bf4898cfaae
2023-03-03T22:27:58.174Z
General Question
v1
How do we create child process from child process
null
null
null
63c6483c5f004bf4898cfaae
2023-03-10T22:10:05.208Z
Help Fix Code
v2
check if username or password is too long
// If username is too long fgets(user_id, MAXLINE, stdin); if(strlen(user_id) > MAX_PASSWORD + 1) { printf(NO_USER); exit(1); } // If password is too long fgets(password, MAXLINE, stdin); if(strlen(password) > MAX_PASSWORD + 1) { printf(NO_USER); exit(1); }
null
null
63c6483c5f004bf4898cfaae
2023-03-17T19:11:16.557Z
General Question
v2
how to write random numbers to a file
null
null
null
63c6483c5f004bf4898cfaae
2023-03-17T19:25:41.437Z
General Question
v2
how to use -vtu4 flag in od to display contents of a binary file?
null
null
null
63c6483c5f004bf4898cfaae
2023-03-24T19:08:50.075Z
General Question
v2
Could you explain the parameters in read() function?
null
null
null
63c6483c5f004bf4898cfaae
2023-03-24T19:47:02.133Z
General Question
v2
How does memmove() work?
null
null
null
63c6483c5f004bf4898cfaae
2023-03-28T17:51:22.221Z
General Question
v2
How to write a message from stdin to socket?
null
null
null
63c6483c5f004bf4898cfaae
2023-03-28T18:02:08.662Z
General Question
v2
how does a server broadcast messages to its connected clients?
null
null
null
63c6483c5f004bf4898cfaae
2023-03-31T21:52:53.095Z
Help Fix Code
v2
Monitor stdin and the socket using select to avoid blocking on either one.
fd_set read_fds; FD_ZERO(&read_fds); FD_SET(sock_fd, &read_fds); FD_SET(STDIN_FILENO, &read_fds); // Read input from the user and send it to the server. Echo any output // received from the server. while (1) { // Read from server if (FD_ISSET(sock_fd, &read_fds)) { num_read = read(sock_fd, buf, BUF_SIZE); } // Read from stdin if (FD_ISSET(STDIN_FILENO, &read_fds)) { num_read = read(STDIN_FILENO, buf, BUF_SIZE); } if (num_read == 0) { break; } buf[num_read] = '\0'; /* * We should really send "\r\n" too, so the server can identify partial * reads, but you are not required to handle partial reads in this lab. */ if (write(sock_fd, buf, num_read) != num_read) { perror("client: write"); close(sock_fd); exit(1); } num_read = read(sock_fd, buf, sizeof(buf) - 1); if (num_read == 0) { break; } buf[num_read] = '\0'; printf("[Server] %s", buf); } close(sock_fd); return 0;
null
null
63c6483c5f004bf4898cfab3
2023-01-18T16:12:04.913Z
General Question
v1
c_helper.py:148: in _t self.assertEqual(stdout, expected_stdout) E AssertionError: '125' != '1\n6\n4161234567\n3' E - 125 E + 1 E 6 E 4161234567 E 3 what is wrong with the code?
null
null
null
63c6483c5f004bf4898cfab3
2023-01-18T16:18:51.771Z
Help Fix Code
v1
null
#include <stdio.h> int main() { char str1[11]; int num; while(scanf("%s\n", str1)==1){ scanf("%d", &num); if (num==-1){ printf("%s\n", str1); }else if (num >=0 && num <=9){ printf("%c\n", str1[num]); }else if (num < -1 || num >9){ printf("ERROR\n"); } } return 0; }
keep asking user for input until input stream is closed
null
63c6483c5f004bf4898cfab3
2023-01-18T16:29:28.002Z
Question from Code
v1
c_helper.py:148: in _t self.assertEqual(stdout, expected_stdout) E AssertionError: '1\n2\n5' != '1\n6\n4161234567\n3' E 1 E - 2 E - 5+ 6 E + 4161234567 E + 3 How to get this test to pass?
#include <stdio.h> int main() { char str1[11]; int num; while(scanf("%s\n", str1)==1){ scanf("%d", &num); if (num==-1){ printf("%s\n", str1); }else if (num >=0 && num <=9){ printf("%c\n", str1[num]); }else if (num < -1 || num >9){ printf("ERROR\n"); } } return 0; }
null
null
63c6483c5f004bf4898cfab3
2023-01-18T16:30:48.853Z
Question from Code
v1
c_helper.py:148: in _t self.assertEqual(stdout, expected_stdout) E AssertionError: '1\n2\n5' != '1\n6\n4161234567\n3' E 1 E - 2 E - 5+ 6 E + 4161234567 E + 3 Why is my code returning the wrong output?
#include <stdio.h> int main() { char str1[11]; int num; while(scanf("%s\n", str1)==1){ scanf("%d", &num); if (num==-1){ printf("%s\n", str1); }else if (num >=0 && num <=9){ printf("%c\n", str1[num]); }else if (num < -1 || num >9){ printf("ERROR\n"); } } return 0; }
null
null
63c6483c5f004bf4898cfab3
2023-01-18T16:36:32.631Z
Help Fix Code
v1
null
#include <stdio.h> int main() { char str1[11]; int num; while(scanf("%s", str1)==1){ scanf("%d", &num); if (num==-1){ printf("%s\n", str1); }else if (num >=0 && num <=9){ printf("%c\n", str1[num]); }else if (num < -1 || num >9){ printf("ERROR\n"); } } return 0; }
c_helper.py:148: in _t self.assertEqual(stdout, expected_stdout) E AssertionError: '1\n2\n5' != '1\n6\n4161234567\n3' E 1 E - 2 E - 5+ 6 E + 4161234567 E + 3 Why is my code returning the wrong output?
null
63c6483c5f004bf4898cfab3
2023-02-05T21:13:46.862Z
General Question
v1
why am I getting a segmentation fault? if (strcmp(curr->name,name)==0){ prev->next=curr->next; //remove user from friend lists for(int i=0; i<MAX_FRIENDS;i++){ //find this user within friends' lists User *f=curr->friends[i]; if(f!=NULL){ int j =0; while(f->friends[j]!=NULL && strcmp(f->friends[j]->name,name)!=0){ j+=1; } if (strcmp(f->friends[j]->name,name)==0){ //shift friends forward to get rid of this user // while(j<MAX_FRIENDS-1){ // f->friends[j]=f->friends[j+1]; // j+=1; // } } } } free(curr); return 0;
null
null
null
63c6483c5f004bf4898cfab3
2023-02-05T21:19:29.218Z
Help Fix Code
v1
null
int delete_user(const char *name, User **user_ptr_del) { User *curr = *user_ptr_del; User *prev=NULL; //find the user while(curr!=NULL && strcmp(curr->name,name)!=0){ prev=curr; curr=curr->next; } //remove the user if (strcmp(curr->name,name)==0){ prev->next=curr->next; //remove user from friend lists for(int i=0; i<MAX_FRIENDS;i++){ //find this user within friends' lists User *f=curr->friends[i]; if(f!=NULL){ int j =0; while(f->friends[j]!=NULL && strcmp(f->friends[j]->name,name)!=0){ j+=1; } if (strcmp(f->friends[j]->name,name)==0){ //shift friends forward to get rid of this user while(j<MAX_FRIENDS-1){ f->friends[j]=f->friends[j+1]; j+=1; } } } } free(curr); return 0; } return 1; }
remove the user with name from the user_ptr_del
null
63c6483c5f004bf4898cfab3
2023-02-05T21:34:18.558Z
Help Fix Code
v1
null
int delete_user(const char *name, User **user_ptr_del) { User *curr = *user_ptr_del; User *prev=NULL; //find the user while(curr!=NULL && strcmp(curr->name,name)!=0){ prev=curr; curr=curr->next; } //remove the user if (strcmp(curr->name,name)==0){ prev->next=curr->next; //remove user from friend lists for(int i=0; i<MAX_FRIENDS;i++){ //find this user within friends' lists User *f=curr->friends[i]; if(f!=NULL){ int j =0; while(f->friends[j]!=NULL && strcmp(f->friends[j]->name,name)!=0){ j+=1; } if (strcmp(f->friends[j]->name,name)==0){ //shift friends forward to get rid of this user while(j<MAX_FRIENDS-1){ f->friends[j]=f->friends[j+1]; j+=1; } } } } free(curr); return 0; } return 1; }
The code is supposed to remove the user with name from the list by setting pointer of the previous user before the user with name to the user after the user with name. It also need to delete all of the user with name from the users friends lists.
null
63c6483c5f004bf4898cfab3
2023-02-05T21:48:58.969Z
Help Fix Code
v1
null
if (strcmp(curr->name,name)==0){ //remove user from friend lists for(int i=0; i<MAX_FRIENDS;i++){ //find this user within friends' lists User *f=curr->friends[i]; if(f!=NULL){ int j =0; while(f->friends[j]!=NULL && strcmp(f->friends[j]->name,name)!=0){ j+=1; } if (strcmp(f->friends[j]->name,name)==0){ //shift friends forward to get rid of this user while(j<MAX_FRIENDS-1){ f->friends[j]=f->friends[j+1]; j+=1; } } } } prev->next=curr->next; free(curr); return 0;
why is there a seg fault occurring?
null
63c6483c5f004bf4898cfab3
2023-02-05T22:17:06.797Z
Help Fix Code
v1
null
User *curr = *user_ptr_del; User *prev=NULL; //find the user while(curr!=NULL && strcmp(curr->name,name)!=0){ prev=curr; curr=curr->next; } //remove the user if (strcmp(curr->name,name)==0){ //remove user from friend lists for(int i=0; i<MAX_FRIENDS;i++){ //find this user within friends' lists User *f=curr->friends[i]; if(f!=NULL){ for(int j=0;j<MAX_FRIENDS;j++){
why am I getting a set fault?
null
63c6483c5f004bf4898cfab3
2023-02-05T22:41:38.987Z
Help Fix Code
v1
null
User *f=curr->friends[i]; if(f!=NULL){ for(int j=0;j<MAX_FRIENDS;j++){ if (f->friends[j]!=NULL){ } }
why is there a set fault?
null
63c6483c5f004bf4898cfab3
2023-02-12T16:28:54.706Z
Question from Code
v1
What will this declaration line become after the program has passed through the C pre-processor?
suppose we have the following line at the top of our program #define MAXNAME = 32; and then the declaration char name[MAXNAME]; in the program.
null
null
63c6483c5f004bf4898cfab3
2023-02-24T01:24:31.478Z
General Question
v1
How to parse file with fgets and fscanf?
null
null
null
63c6483c5f004bf4898cfab3
2023-02-25T03:15:18.971Z
Help Write Code
v1
null
null
null
how to write a function that will parse a Makefile and separate lines into actions, target, dependencies into linked list structures?
63c6483c5f004bf4898cfab3
2023-03-08T15:12:02.381Z
Question from Code
v1
what does tt.tv_sec refer to when struct stat st refers to a file?
struct timespec tt; struct stat st; tt.tv_sec=st.st_mtime;
null
null
63c6483c5f004bf4898cfab3
2023-03-09T17:00:55.825Z
Help Fix Code
v2
Why is this giving an error error: member reference base type '__darwin_time_t' (aka 'long') is not a structure or union
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> int main(){ struct stat sd; //struct timespec td; char *path=malloc(9); strncpy(path, "file.txt",8); path[8]='\0'; stat(path, &sd); //td.tv_sec=sd.st_mtime; printf("%lu.%lu\n",sd.st_mtime, sd.st_mtime.tv_nsec); return 0; }
null
null
63c6483e5f004bf4898cfac7
2023-01-18T20:09:39.816Z
Explain Code
v1
null
int main(int argc, char **argv) { int size = argc - 1; int *score_card[size]; for (int i = 0; i < size; i++) { // NOTE: We haven't covered malloc yet, so don't worry about this line. score_card[i] = malloc(sizeof(int)); *(score_card[i]) = strtol(argv[i + 1], NULL, 10); } printf("Sum: %d\n", sum_card(score_card, size)); return 0; }
null
null
63c6483e5f004bf4898cfac7
2023-01-18T20:37:37.240Z
General Question
v1
What determines the return for scanf()?
null
null
null
63c6483e5f004bf4898cfac7
2023-01-29T19:01:54.730Z
General Question
v1
Why is strcpy() unsafe?
null
null
null
63c6483f5f004bf4898cfacc
2023-01-18T01:27:49.083Z
General Question
v1
what is wrong with my code
null
null
null
63c6483f5f004bf4898cfacc
2023-01-18T01:29:17.226Z
Help Fix Code
v1
null
int main() { // These variables have been assigned hidden values: int secret; int *another_secret; // Declare a variable named secret_pt and make it point to secret: int *secret_pt = &secret; // Add the value pointed to by another_secret to the // value pointed to by secret_pt. // Do not change the address assigned to secret_pt, and don't explicitly set secret. secret_pt = secret_pt + *another_secret; return 0; }
Add the value pointed to by another_secret to the value pointed to by secret_pt. Do not change the address assigned to secret_pt, and don't explicitly set secret.
null
63c6483f5f004bf4898cfacc
2023-01-18T01:56:03.306Z
Explain Code
v1
null
int main() { int i = 81; int *pt = &i; int **pt_ptr = &pt; int *r= *pt_ptr; int k = *r; // We don't actually need the intermediate value r. // We can dereference pt_ptr twice like this. int k1 = **pt_ptr; // We can even have triple pointers. int ***pt_ptr_ptr = &pt_ptr; int k2 = ***pt_ptr_ptr; return 0; }
null
null
63c6483f5f004bf4898cfacc
2023-01-18T01:57:15.800Z
General Question
v1
on line 7 why does *r = *pt_ptr and not **pt_ptr
null
null
null
63c6483f5f004bf4898cfacc
2023-01-18T02:06:04.148Z
Explain Code
v1
null
int x = 4; int *y = &x; int **z = &y; int q;
null
null
63c6483f5f004bf4898cfacc
2023-01-19T20:09:27.913Z
Explain Code
v1
null
#include <stdio.h> #include <stdlib.h> int main() { int allocated_amount; // Set the value of allocated_amount: return 0; }
null
null
63c6483f5f004bf4898cfacc
2023-01-19T20:10:18.944Z
General Question
v1
How to set the allocated_amount variable to the exact amount of space that should be allocated?
null
null
null
63c6483f5f004bf4898cfacc
2023-01-19T20:11:09.151Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> int main() { int allocated_amount; // Set the value of allocated_amount: allocated_amount = malloc(sizeof(int)); return 0; }
why doesn't this work?
null
63c6483f5f004bf4898cfacc
2023-01-19T20:11:34.808Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> int main() { int allocated_amount; // Set the value of allocated_amount: *allocated_amount = malloc(sizeof(int)); return 0; }
null
null
63c6483f5f004bf4898cfacc
2023-01-19T20:13:11.658Z
Help Fix Code
v1
null
int main(int argc, char **argv) { float *rainfall; float rain_today; // rainfall has been dynamically allocated space for a floating point number. // Both rainfall and rain_today have been initialized in hidden code. // Assign the amount in rain_today to the space rainfall points to. return 0; }
null
null
63c648415f004bf4898cfadb
2023-01-19T23:05:12.030Z
General Question
v1
How to check when standard input is closed using scanf?
null
null
null
63c648415f004bf4898cfadb
2023-01-27T11:43:28.585Z
Question from Code
v1
Why does this code give a segmentation fault?
#include <stdlib.h> #include <stdio.h> /* * Define a function void fib(...) below. This function takes parameter n * and generates the first n values in the Fibonacci sequence. Recall that this * sequence is defined as: * 0, 1, 1, 2, 3, 5, ... , fib[n] = fib[n-2] + fib[n-1], ... * The values should be stored in a dynamically-allocated array composed of * exactly the correct number of integers. The values should be returned * through a pointer parameter passed in as the first argument. * * See the main function for an example call to fib. * Pay attention to the expected type of fib's parameters. */ /* Write your solution here */ void fib(int **fib_ptr, int n){ *fib_ptr = malloc(sizeof (int) * n); if (n == 1){ *fib_ptr[0] = 0; } else if (n == 2){ *fib_ptr[0] = 0; *fib_ptr[1] = 1; } else{ *fib_ptr[0] = 0; *fib_ptr[1] = 1; for (int i = 2; i < n; i++){ *fib_ptr[i] = *fib_ptr[i - 2] + *fib_ptr[i - 1]; } } } int main(int argc, char **argv) { /* do not change this main function */ int count = strtol(argv[1], NULL, 10); int *fib_sequence; fib(&fib_sequence, count); for (int i = 0; i < count; i++) { printf("%d ", fib_sequence[i]); } free(fib_sequence); return 0; }
null
null
63c648415f004bf4898cfadb
2023-01-27T18:03:29.109Z
General Question
v1
How to use strtol?
null
null
null
63c648415f004bf4898cfadb
2023-01-27T18:06:53.191Z
General Question
v1
How to use argc and argv?
null
null
null