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
⌀ |
---|---|---|---|---|---|---|---|
63c648ff5f004bf4898d01ac
|
2023-03-17T04:40:23.004Z
|
Help Fix Code
|
v2
|
Should create a signal
|
struct itimerval new; // it_val_old; // set a timer value
struct sigaction action;
action.sa_handler = handler;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
sigaction(SIGPROF, &action, NULL); // set the action
new.it_interval.tv_usec = 0; // set next value microseconds
new.it_interval.tv_sec = seconds; // set next value seconds
new.it_value.tv_usec = 0; // set microseconds to zero for current value
new.it_value.tv_sec = seconds; // set seconds to seconds for current value
// printf("Setittimer: %d\n", setitimer(ITIMER_PROF, &it_val_new, NULL));
int sig_return;
if((sig_return = setitimer(ITIMER_PROF, &new, NULL)) == -1){
fprintf(stderr, "Error: setitmer\n");
perror("setitimer");
exit(1);
}
| null | null |
63c648ff5f004bf4898d01ac
|
2023-03-24T23:05:53.936Z
|
General Question
|
v2
|
what are c sockets
| null | null | null |
63c648ff5f004bf4898d01ac
|
2023-04-25T21:48:48.564Z
|
General Question
|
v2
|
what's the difference between binary and text files
| null | null | null |
63c648ff5f004bf4898d01ac
|
2023-04-25T21:49:34.043Z
|
General Question
|
v2
|
give me an example of a binary file
| null | null | null |
63c649005f004bf4898d01b1
|
2023-01-18T04:27:37.109Z
|
Explain Code
|
v1
| null |
void swapA(int *num1, int *num2) {
int *temp = num1;
num1 = num2;
num2 = temp;
| null | null |
63c649005f004bf4898d01b1
|
2023-01-18T04:28:56.754Z
|
General Question
|
v1
|
what is num1 pointed to
| null | null | null |
63c649005f004bf4898d01b1
|
2023-01-18T20:55:29.058Z
|
Question from Code
|
v1
|
what is num1
|
void swapA(int *num1, int *num2) {
int *temp = num1;
num1 = num2;
num2 = temp;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-27T04:25:57.990Z
|
Question from Code
|
v1
|
what does thus function do
|
void fib(int **fs,int count){
int *f=(int*)malloc(sizeof(int)*count);
*(f)=0;
*(f+1)=1;
for(int i=2;i<count;i++){
*(f+i)=*(f+i-2)+*(f+i-1);
}
*fs=f;
return;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-27T04:26:52.909Z
|
Explain Code
|
v1
| null |
void fib(int **fs,int count){
int *f=(int*)malloc(sizeof(int)*count);
*(f)=0;
*(f+1)=1;
for(int i=2;i<count;i++){
*(f+i)=*(f+i-2)+*(f+i-1);
}
*fs=f;
return;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-27T20:35:17.779Z
|
Explain Code
|
v1
| null |
int **split_array(const int *s, int length) {
int **p;
p=(int**)malloc(sizeof(int*)*2);
int l1,l2;
if(length%2==0){
l1=l2=length/2;
}
else {
l1=length/2+1;
l2=length/2;
}
p[0]=(int*)malloc(sizeof(int)*l1);
p[1]=(int*)malloc(sizeof(int)*l2);
l1=l2=0;
for(int i=0;i<length;i++){
if(i%2==0){
p[0][l1++]=s[i];
}
else p[1][l2++]=s[i];
}
return p;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-27T20:51:18.184Z
|
Explain Code
|
v1
| null |
int **split_array(const int *s, int length) {
int **p;
p=(int**)malloc(sizeof(int*)*2);
int l1,l2;
if(length%2==0){
l1=l2=length/2;
}
else {
l1=length/2+1;
l2=length/2;
}
p[0]=(int*)malloc(sizeof(int)*l1);
p[1]=(int*)malloc(sizeof(int)*l2);
l1=l2=0;
for(int i=0;i<length;i++){
if(i%2==0){
p[0][l1++]=s[i];
}
else p[1][l2++]=s[i];
}
return p;
}
int *build_array(char **strs, int size) {
int *p=(int*)malloc( sizeof(int)*size);
int j;
for(int i=0;i<size;i++){
p[i]=0;
}
for(int i=1;i<=size;i++){
j=0;
while(strs[i][j]!='\0'){
p[i-1]=p[i-1]*10+strs[i][j]-'0';
j++;
}
}
return p;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-27T20:58:06.823Z
|
Question from Code
|
v1
|
why does line 34 use '0'
|
int **split_array(const int *s, int length) {
int **p;
p=(int**)malloc(sizeof(int*)*2);
int l1,l2;
if(length%2==0){
l1=l2=length/2;
}
else {
l1=length/2+1;
l2=length/2;
}
p[0]=(int*)malloc(sizeof(int)*l1);
p[1]=(int*)malloc(sizeof(int)*l2);
l1=l2=0;
for(int i=0;i<length;i++){
if(i%2==0){
p[0][l1++]=s[i];
}
else p[1][l2++]=s[i];
}
return p;
}
int *build_array(char **strs, int size) {
int *p=(int*)malloc( sizeof(int)*size);
int j;
for(int i=0;i<size;i++){
p[i]=0;
}
for(int i=1;i<=size;i++){
j=0;
while(strs[i][j]!='\0'){
p[i-1]=p[i-1]*10+strs[i][j]-'0';
j++;
}
}
return p;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-27T20:59:18.737Z
|
Question from Code
|
v1
|
what does line 34 do
|
int **split_array(const int *s, int length) {
int **p;
p=(int**)malloc(sizeof(int*)*2);
int l1,l2;
if(length%2==0){
l1=l2=length/2;
}
else {
l1=length/2+1;
l2=length/2;
}
p[0]=(int*)malloc(sizeof(int)*l1);
p[1]=(int*)malloc(sizeof(int)*l2);
l1=l2=0;
for(int i=0;i<length;i++){
if(i%2==0){
p[0][l1++]=s[i];
}
else p[1][l2++]=s[i];
}
return p;
}
int *build_array(char **strs, int size) {
int *p=(int*)malloc( sizeof(int)*size);
int j;
for(int i=0;i<size;i++){
p[i]=0;
}
for(int i=1;i<=size;i++){
j=0;
while(strs[i][j]!='\0'){
p[i-1]=p[i-1]*10+strs[i][j]-'0';
j++;
}
}
return p;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-30T00:41:17.800Z
|
Explain Code
|
v1
| null |
int check_sin(int *sin_array) {
for(int i=0;i<9;i++){
sin_array[i]=sin_array[i]*(i%2==0?1:2);
}
for(int i=0;i<9;i++){
while(sin_array[i]>=10){
sin_array[i]/=10;
}
}
int sum=0;
for(int i=0;i<9;i++){
sum+=sin_array[i];
}
if(sum%10==0){
return 0;
}
return 1;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-30T01:12:12.678Z
|
Explain Code
|
v1
| null |
int check_sin(int *sin_array) {
for(int i=0;i<9;i++){
sin_array[i]=sin_array[i]*(i%2==0?1:2);
}
for(int i=0;i<9;i++){
while(sin_array[i]>=10){
sin_array[i]/=10;
}
}
int sum=0;
for(int i=0;i<9;i++){
sum+=sin_array[i];
}
if(sum%10==0){
return 0;
}
return 1;
}
int populate_array(int sin, int *sin_array) {
int i=0;
while(sin!=0){
sin_array[i++]+=sin%10;
sin/=10;
}
if(i!=9){
return 1;
}
return 0;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-30T01:13:48.040Z
|
Question from Code
|
v1
|
what does populate_array do
|
int check_sin(int *sin_array) {
for(int i=0;i<9;i++){
sin_array[i]=sin_array[i]*(i%2==0?1:2);
}
for(int i=0;i<9;i++){
while(sin_array[i]>=10){
sin_array[i]/=10;
}
}
int sum=0;
for(int i=0;i<9;i++){
sum+=sin_array[i];
}
if(sum%10==0){
return 0;
}
return 1;
}
int populate_array(int sin, int *sin_array) {
int i=0;
while(sin!=0){
sin_array[i++]+=sin%10;
sin/=10;
}
if(i!=9){
return 1;
}
return 0;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-01-30T02:09:00.284Z
|
Explain Code
|
v1
| null |
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 SIN given as a command line argument.
else {
int sin=0;
int *sin_array=(int*)malloc(sizeof(int)*9);
for(int i=0;i<9;i++){
sin=sin*10+*argv[i]-'0';
}
if(populate_array(sin,sin_array)==1){
return 1;
}
if(check_sin(sin_array)!=0){
return 1;
}
}
return 0;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-03-14T02:10:30.381Z
|
Question from Code
|
v2
|
What does the program print to stderr if the user presses Ctrl+C at the moment when the program is at position B?
|
int x = 5;
void handler(int sig) {
x += 3;
fprintf(stderr, "inside %d ", x);
}
int main() {
fprintf(stderr, "start ");
// POSITION A
struct sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act, NULL);
// POSITION B
x += 2;
// POSITION C
fprintf(stderr, "outside %d", x);
return 0;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-03-14T02:15:41.413Z
|
General Question
|
v2
|
what are the library files for this
| null | null | null |
63c649005f004bf4898d01b1
|
2023-04-18T18:08:11.858Z
|
Question from Code
|
v2
|
What will be the output of the following program fragment?
|
#define SUPERVISOR(regular) regular + 5
int main() {
int regular_pay = 20;
int hours_worked = 10;
printf("pay is %d\n", (hours_worked * SUPERVISOR(regular_pay)));
// rest omitted
}
| null | null |
63c649005f004bf4898d01b1
|
2023-04-18T18:09:18.564Z
|
Question from Code
|
v2
|
What will be the output of the following program fragment?
|
#define SUPERVISOR(regular) regular + 5
int main() {
int regular_pay = 20;
int hours_worked = 10;
printf("pay is %d\n", (hours_worked * SUPERVISOR(regular_pay)));
// rest omitted
}
| null | null |
63c649005f004bf4898d01b1
|
2023-04-18T18:10:02.035Z
|
Explain Code
|
v2
| null |
#define SUPERVISOR(regular) regular + 5
int main() {
int regular_pay = 20;
int hours_worked = 10;
printf("pay is %d\n", (hours_worked * SUPERVISOR(regular_pay)));
// rest omitted
}
| null | null |
63c649005f004bf4898d01b1
|
2023-04-19T21:53:00.265Z
|
Explain Code
|
v2
| null |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void Close(int fd) {
if (close(fd) != 0) { // in the 10 am class the mistake in
perror("close"); // the code was in this wrapper function
exit(1);
}
}
int main(int argc, char **argv) {
// Declare any variables you need
int fd[argc][2];
int one_value;
// Write the code to loop over the command line arguments
for (int i = 1; i < argc; i++) {
// Call pipe before we fork
if (pipe(fd[i]) == -1) {
perror("pipe");
exit(1);
}
// Call fork
int result = fork();
if (result < 0) {
perror("fork");
exit(1);
} else if (result == 0) {
// Child only writes to the pipe, so close reading end
Close(fd[i][0]);
// Before we forked, parent had open the reading ends to
// all previously forked children; so close those.
for (int j = 1; j < i; j++) {
Close(fd[j][0]);
}
// Now do the work - write the value in binary to the pipe
int length = strlen(argv[i]);
write(fd[i][1], &length, sizeof(int));
// Close the pipe since we are done with it.
Close(fd[i][1]);
exit(0);
} else {
// In the parent, but before doing the next loop iteration,
// close the end of the pipe that we don't want open
Close(fd[i][1]);
}
}
// Only the parent gets here
int sum = 0;
for (int i = 1; i < argc; i++) {
// Read one integer from each child
read(fd[i][0], &one_value, sizeof(int));
printf("I just read %d from pipe %d\n", one_value, i);
sum += one_value;
}
printf("Sum is %d\n", sum);
return 0;
}
| null | null |
63c649005f004bf4898d01b1
|
2023-04-20T17:36:51.401Z
|
Explain Code
|
v2
| null |
int x = 5;
void handler(int sig) {
x += 3;
fprintf(stderr, "inside %d ", x);
}
int main() {
fprintf(stderr, "start ");
// POSITION A
struct sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act, NULL);
// POSITION B
x += 2;
// POSITION C
fprintf(stderr, "outside %d", x);
return 0;
}
| null | null |
63c649005f004bf4898d01b6
|
2023-01-18T03:46:29.024Z
|
General Question
|
v1
|
what is the purpose of CSC209
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-18T03:47:00.192Z
|
General Question
|
v1
|
what is the main idea of lab 2
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-18T06:09:52.824Z
|
Help Fix Code
|
v1
| null |
void invest(double *principal, double rate) {
principal = principal * rate;
}
| null | null |
63c649005f004bf4898d01b6
|
2023-01-18T06:35:23.232Z
|
General Question
|
v1
|
how do i read linux manual
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-18T06:36:17.317Z
|
General Question
|
v1
|
how do i determine what the return value is for the function scanf when the input stream is closed
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-18T06:58:59.183Z
|
General Question
|
v1
|
what can i ask
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-19T03:05:40.300Z
|
General Question
|
v1
|
how do i allocate an exact amount of memory for a variable
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-19T03:07:23.517Z
|
Help Fix Code
|
v1
| null |
int main() {
int allocated_amount;
// Set the value of allocated_amount;
return 0;
}
|
set the value of allocated_amount
| null |
63c649005f004bf4898d01b6
|
2023-01-19T03:09:22.199Z
|
Help Fix Code
|
v1
| null |
int main() {
int allocated_amount;
// Set the value of allocated_amount:
return 0;
}
|
set the allocated_amount variable to the exact amount of space that should be allocated and pointed to by float *rainfall.
| null |
63c649005f004bf4898d01b6
|
2023-01-22T01:23:01.459Z
|
General Question
|
v1
|
A program should have one more call to free than the number of calls it has to malloc.
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-22T01:23:42.206Z
|
General Question
|
v1
|
The expression *p[0] is the same as p[0][0].
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-22T01:24:00.927Z
|
General Question
|
v1
|
We typically free the pieces of a nested data-structure from the "bottom-up".
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-22T01:24:19.886Z
|
General Question
|
v1
|
We typically free the pieces of a nested data-structure from the "bottom-up".
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-22T01:24:47.571Z
|
General Question
|
v1
|
We typically allocate the pieces of a nested data-structure from the "bottom-up".
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-22T01:25:25.483Z
|
General Question
|
v1
|
Calls to free should come in the same order as the corresponding calls to malloc.
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-22T23:13:18.255Z
|
General Question
|
v1
|
Instead you could run ls -l and pipe its output to your program
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-24T00:01:14.285Z
|
General Question
|
v1
|
how do i handle the output of ls -l in my program?
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-24T00:02:02.375Z
|
General Question
|
v1
|
what does fscanf do
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-24T00:02:30.918Z
|
General Question
|
v1
|
what does scanf do
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-24T00:08:22.218Z
|
General Question
|
v1
|
what does ls -l do
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-25T22:32:21.371Z
|
General Question
|
v1
|
how do i scan a line of strings using scanf?
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-25T22:33:21.965Z
|
Help Write Code
|
v1
| null | null | null |
i want to read the output of the command ls -l
|
63c649005f004bf4898d01b6
|
2023-01-25T22:33:42.791Z
|
General Question
|
v1
|
i want to read the output of the command ls -l using scanf
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-25T22:36:47.943Z
|
General Question
|
v1
|
how to scanf an entire line of input
| null | null | null |
63c649005f004bf4898d01b6
|
2023-01-28T01:40:16.960Z
|
Help Fix Code
|
v1
| null |
void update_contact(struct *contact, char *name, int number, char *address) {
strcpy((*contact).name, name);
(*contact).phone_number = number;
strcpy((*contact), address);
}
|
mutates a structure
| null |
63c649005f004bf4898d01b6
|
2023-01-28T01:53:57.221Z
|
Help Fix Code
|
v1
| null |
struct Node {
int value;
struct *Node next;
}
|
create a node struct
| null |
63c649005f004bf4898d01b6
|
2023-02-05T02:16:22.172Z
|
Question from Code
|
v1
|
why is there a word User at the end?
|
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;
| null | null |
63c649005f004bf4898d01b6
|
2023-02-05T02:16:58.605Z
|
General Question
|
v1
|
how can i instantiate this struct?
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-05T02:19:34.127Z
|
Help Fix Code
|
v1
| null |
struct user new_user;
new_user.name = name;
|
why do i get an error
| null |
63c649005f004bf4898d01b6
|
2023-02-05T02:25:18.637Z
|
General Question
|
v1
|
how can i assigna value to the next value of a node struct
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-05T02:27:53.769Z
|
Help Fix Code
|
v1
| null |
// loop through user linked list
User *curr = user_ptr_add;
while (curr != NULL) {
if (curr->name = name) {
return 1;
} else if (curr->next = NULL) {
curr->next->new_user;
return 0;
}
curr = curr->next;
}
|
loop through linked list
| null |
63c649005f004bf4898d01b6
|
2023-02-05T02:32:54.581Z
|
Help Fix Code
|
v1
| null |
// create new user
User *new_user;
strncpy(new_user->name, name, sizeof(new_user));
|
assign a value to the string attribute of new_user
| null |
63c649005f004bf4898d01b6
|
2023-02-05T02:59:47.055Z
|
General Question
|
v1
|
how can i check if a file exists or cannot be openned?
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-05T03:05:14.108Z
|
Help Fix Code
|
v1
| null |
user->profile_pic = filename;
|
i want to assign filename to the profile_pic attribute of user
| null |
63c649005f004bf4898d01b6
|
2023-02-05T03:07:14.824Z
|
General Question
|
v1
|
what does strncpy return
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-05T03:13:03.374Z
|
Help Fix Code
|
v1
| null |
/*
* Print the usernames of all users in the list starting at curr.
* Names should be printed to standard output, one per line.
*/
void list_users(const User *curr) {
// loop through linked list
User *curr = curr;
while (curr != NULL) {
printf("%s\n", curr->name);
curr = curr->next;
}
}
|
print all linked list nodes
| null |
63c649005f004bf4898d01b6
|
2023-02-06T22:54:09.523Z
|
Explain Code
|
v1
| null |
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;
| null | null |
63c649005f004bf4898d01b6
|
2023-02-06T23:33:12.628Z
|
Help Fix Code
|
v1
| null |
User *friend_a = NULL;
User *curr = head;
while (curr != NULL) {
if (strcmp(curr->name, name1) == 0) {
friend_a = curr;
}
curr = curr->next;
}
|
check if a User node with the name attribute name1 is in a linked list
| null |
63c649005f004bf4898d01b6
|
2023-02-08T17:36:31.426Z
|
Explain Code
|
v1
| null |
#define MAXNAME = 32;
char name[MAXNAME];
| null | null |
63c649005f004bf4898d01b6
|
2023-02-09T01:31:08.775Z
|
Help Fix Code
|
v1
| null |
int are_they_friends(struct user a, struct user b) {
// check if b is in a's friends list
int a_friends_num = sizeof(a.friends) / sizeof(a.friends[0]);
for (int i = 0; i < a_friends_num; i++) {
if (a.friends[i] == b) {
return 0; //true
}
}
return 1; //false
}
|
checks whether user b is in an array attribute, friends, of user a
| null |
63c649005f004bf4898d01b6
|
2023-02-09T02:07:14.960Z
|
Help Fix Code
|
v1
| null |
new_post->author = author.name;
|
set the author of a post struct to name
| null |
63c649005f004bf4898d01b6
|
2023-02-11T22:17:14.472Z
|
General Question
|
v1
|
what is valgrind
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-11T22:19:06.011Z
|
General Question
|
v1
|
how to I allocate memory for my struct attributes
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-11T22:27:15.286Z
|
General Question
|
v1
|
how can i create a new struct instance and malloc its attributes
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-11T22:37:58.031Z
|
General Question
|
v1
|
when do i need to allocate memory for my struct?
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-11T22:43:04.058Z
|
Help Fix Code
|
v1
| null |
User *new_user = malloc(sizeof(struct user));
new_user->name = malloc(MAX_NAME);
|
create a new struct instance called new_user and allocate memory for its name attribute
| null |
63c649005f004bf4898d01b6
|
2023-02-11T22:43:58.422Z
|
Help Fix Code
|
v1
| null |
User *new_user = malloc(sizeof(User));
new_user->name = malloc(MAX_NAME);
|
create a new struct instance called new_user and allocate memory for its name attribute
| null |
63c649005f004bf4898d01b6
|
2023-02-11T22:45:33.427Z
|
Help Fix Code
|
v1
| null |
User *new_user = malloc(sizeof(User));
new_user->name = malloc(MAX_NAME * sizeof(char));
|
create a new struct instance called new_user and allocate memory for its name attribute
| null |
63c649005f004bf4898d01b6
|
2023-02-11T22:46:36.818Z
|
Help Write Code
|
v1
| null | null | null |
create a new struct instance in a helper function and allocate memory for it and its attributes
|
63c649005f004bf4898d01b6
|
2023-02-12T00:07:45.388Z
|
Help Fix Code
|
v1
| null |
User *find_user(const char *name, const User *head) {
// loop through linked list
User *curr = (User *) head;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
return curr;
}
curr = curr->next;
}
// user not found
return NULL;
}
|
return a pointer to the user with this name. the users are stored as a linked list
| null |
63c649005f004bf4898d01b6
|
2023-02-12T00:09:06.309Z
|
Help Fix Code
|
v1
| null |
void list_users(const User *curr) {
// loop through linked list
while (curr != NULL) {
printf("%s\n", curr->name);
curr = curr->next;
}
}
|
loop through the users linked list and print each user's name attribute
| null |
63c649005f004bf4898d01b6
|
2023-02-12T00:59:32.762Z
|
Help Fix Code
|
v1
| null |
int create_user(const char *name, User **user_ptr_add) {
// if name too long
if (strlen(name) > 32) {
return 2;
}
// create new user
User *new_user_ptr = (User *)malloc(sizeof(User));
//new_user_ptr->name = (char *)malloc(MAX_NAME * sizeof(char));
strncpy(new_user_ptr->name, name, sizeof(new_user_ptr->name));
// if head is NULL new user is head
if (*user_ptr_add == NULL) {
*user_ptr_add = new_user_ptr;
return 0;
} else {
// else add user to tail
User *curr = *user_ptr_add;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
return 1;
} else if (curr->next == NULL) {
curr->next = new_user_ptr;
return 0;
}
curr = curr->next;
}
}
// not reachable
return -1;
}
|
Create a new user with the given name. Insert it at the tail of the list of users whose head is pointed to by *user_ptr_add.
* Return:
* - 0 if successful
* - 1 if a user by this name already exists in this list
* - 2 if the given name cannot fit in the 'name' array
* (don't forget about the null terminator)
| null |
63c649005f004bf4898d01b6
|
2023-02-12T01:28:41.596Z
|
Help Fix Code
|
v1
| null |
User *new_user_ptr = (User *) malloc(sizeof(User));
*new_user_ptr->name = (char *) malloc(MAX_NAME * sizeof(char));
strncpy(new_user_ptr->name, name, sizeof(new_user_ptr->name));
*new_user_ptr->profile_pic = (char *) malloc(MAX_NAME * sizeof(char));
*new_user_ptr->first_post = (Post *) malloc(sizeof(Post));
*new_user_ptr->friends = (User *) malloc(MAX_FRIENDS * sizeof(User));
*new_user_ptr->profile_pic = (User *) malloc(sizeof(User));
|
allocate memory for each attribute of the struct user
| null |
63c649005f004bf4898d01b6
|
2023-02-12T21:57:31.305Z
|
General Question
|
v1
|
how do i use gdb
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-12T21:58:10.338Z
|
General Question
|
v1
|
how do i run valgrind
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-12T22:23:56.746Z
|
Help Fix Code
|
v1
| null |
int num_friends = sizeof(user->friends) / sizeof(user->friends[0]);
for (int i = 0; i < num_friends; i++) {
printf("%s\n", user->friends[i]->name);
}
|
loop through all friends in the user's friends array attribute and print their names
| null |
63c649005f004bf4898d01b6
|
2023-02-12T23:02:05.420Z
|
Help Fix Code
|
v1
| null |
strncpy(new_post->c, contents, strlen(contents));
|
copy the contents argument into the c attribute of the new_post struct
| null |
63c649005f004bf4898d01b6
|
2023-02-13T00:53:38.588Z
|
Help Fix Code
|
v1
| null |
// delete deletee from linked list of users
// case a: deletee is head of linked list
if (prev == NULL) {
curr = curr->next;
} else { // case b: deletee is not head of linked list
prev->next = curr->next;
}
// deallocate curr
free(curr);
|
delete the node curr from a linked list
| null |
63c649005f004bf4898d01b6
|
2023-02-13T01:05:41.850Z
|
Help Fix Code
|
v1
| null |
deletee = user_ptr_del;
user_ptr_del = user_ptr_del->next;
free(user_ptr_del);
|
delete the first node in a linked list. user_ptr_del is a double pointer
| null |
63c649005f004bf4898d01b6
|
2023-02-13T01:06:38.442Z
|
Help Fix Code
|
v1
| null |
deletee = user_ptr_del;
user_ptr_del = (*user_ptr_del)->next;
free(deletee);
|
delete the first node in a linked list. user_ptr_del is a double pointer
| null |
63c649005f004bf4898d01b6
|
2023-02-13T03:27:40.323Z
|
Help Fix Code
|
v1
| null |
(*user_ptr_del)->next = curr->next->next;
*user_ptr_del = curr->next;
free(curr);
|
delete first node of a linked list
| null |
63c649005f004bf4898d01b6
|
2023-02-15T00:13:56.105Z
|
Help Fix Code
|
v1
| null |
User *new_user_ptr = malloc(sizeof(User));
|
allocate memory for a new User struct
| null |
63c649005f004bf4898d01b6
|
2023-02-15T00:14:25.181Z
|
Help Fix Code
|
v1
| null |
User *new_user_ptr = (User *) malloc(sizeof(User));
|
allocate memory for a User struct
| null |
63c649005f004bf4898d01b6
|
2023-02-15T23:07:44.903Z
|
General Question
|
v1
|
how can i use fgets to print a line of a certain length and if its too long to print it on the next line?
| null | null | null |
63c649005f004bf4898d01b6
|
2023-02-24T04:38:14.863Z
|
General Question
|
v1
|
how can i read a line of char from a file, then put the words into an array of strings?
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-13T19:28:35.890Z
|
General Question
|
v2
|
how do i use gdb
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-14T02:17:52.930Z
|
General Question
|
v2
|
how do i use execvp
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-14T02:25:13.395Z
|
General Question
|
v2
|
how can i make the parent process wait for the child process to complete?
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-15T00:45:24.190Z
|
General Question
|
v2
|
if a makefile rule doesnt have any dependencies, does the rule still execute?
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-15T01:11:06.122Z
|
General Question
|
v2
|
what does the function stat return if a file does not exist
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-15T01:15:20.208Z
|
General Question
|
v2
|
can a rule in a makefile have no dependencies and no actions
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-15T01:41:20.512Z
|
General Question
|
v2
|
how can i check the difference in last modified time for two files
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-15T02:49:52.366Z
|
General Question
|
v2
|
is the child process' pid 0
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-15T02:55:03.552Z
|
General Question
|
v2
|
collect2: error: ld returned 1 exit status
what does that error mean
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-15T19:25:10.590Z
|
General Question
|
v2
|
how can i check if a struct has a pointer pointing to it
| null | null | null |
63c649005f004bf4898d01b6
|
2023-03-29T05:54:21.467Z
|
General Question
|
v2
|
can you tell me what lab 11 is about
| null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.