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
⌀ |
---|---|---|---|---|---|---|---|
63c6481a5f004bf4898cf978 | 2023-01-18T00:23:54.961Z | General Question | v1 | why wont this work?
int main(int argc, char **argv) {
char str[10];
int num;
scanf("%s %d", str, &num);
if (num == -1) {
printf("%s", str);
} else if (0 <= num && num < 10) {
printf("%s", *(&str+num));
} else {
printf("ERROR");
}
} | null | null | null |
63c6481a5f004bf4898cf978 | 2023-01-23T15:04:36.960Z | General Question | v1 | how do you make an array of an array of strings in C | null | null | null |
63c6481a5f004bf4898cf978 | 2023-01-23T15:33:48.088Z | General Question | v1 | How to convert a string to an integer | null | null | null |
63c6481a5f004bf4898cf978 | 2023-02-28T03:41:36.060Z | General Question | v1 | How do I make a dynamically sized array in C | null | null | null |
63c6481a5f004bf4898cf978 | 2023-02-28T03:42:02.541Z | General Question | v1 | how to make an arraylist in C like python and how to append to it | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-18T23:55:38.328Z | General Question | v1 | what type is scanf output | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-22T21:21:57.932Z | General Question | v1 | is the output of ls -l a string
| null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-22T21:26:14.498Z | General Question | v1 | how do you print an initialized integer | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-22T21:27:50.354Z | General Question | v1 | how do you skip a line in the input stream | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-22T21:29:18.828Z | General Question | v1 | how do i compile a file | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-22T21:32:49.190Z | General Question | v1 | how do i put ls into standard input of a executable | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-22T21:36:31.599Z | General Question | v1 | can you alternate between fgets and fscan for the same file | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-22T22:24:25.124Z | General Question | v1 | how do you remove the first element from a string | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-23T00:19:34.601Z | General Question | v1 | what is pipe in c | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-24T00:12:43.296Z | General Question | v1 | how to compile two programs at once | null | null | null |
63c6481c5f004bf4898cf987 | 2023-01-24T23:14:46.366Z | Help Fix Code | v1 | null | void fib(int **fib_sequence, int count){
*fib_sequence = malloc(sizeof(int) * count);
if(count >= 1){
*fib_sequence[0] = 0;
}
printf("HI\n");
if(count >= 2){
*fib_sequence[1] = 1;
int i;
for(i = 2; i < count; i++){
*fib_sequence[i] = *fib_sequence[i - 1] + *fib_sequence[i - 2];
}
}
} | null | null |
63c6481c5f004bf4898cf987 | 2023-01-24T23:19:20.495Z | Question from Code | v1 | why am i getting a segmentation error | void fib(int **fib_sequence, int count){
*fib_sequence = malloc(sizeof(int) * count);
if(count >= 1){
*fib_sequence[0] = 0;
}
printf("HI\n");
if(count >= 2){
*fib_sequence[1] = 1;
int i;
for(i = 2; i < count; i++){
*fib_sequence[i] = *fib_sequence[i - 1] + *fib_sequence[i - 2];
}
}
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-01T20:39:07.452Z | General Question | v1 | how to compare strings | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-01T20:47:27.271Z | General Question | v1 | does strlen include the null terminator | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-01T20:53:53.368Z | General Question | v1 | how to trim a string | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-01T20:54:35.044Z | General Question | v1 | how to get a sub string | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-01T22:36:47.518Z | General Question | v1 | how to use strncat | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T02:25:43.028Z | General Question | v1 | is the struct stored in the stack | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T02:28:43.117Z | General Question | v1 | does strlen count the null terminator | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T02:38:55.080Z | Question from Code | v1 | why am i getting an error | int create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while(*user_ptr_add != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
return -1;
}
*user_ptr_add = user_ptr_add->next;
}
struct user add;
strcpy(add.name, name);
user_ptr_add->next = &add;
return -1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T02:49:08.368Z | Question from Code | v1 | why am i getting a segmentation fault | 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 create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while(user_ptr_add != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
printf("%s", (**user_ptr_add).name);
return -1;
}
*user_ptr_add = (**user_ptr_add).next;
}
User add;
strcpy(add.name, name);
(**user_ptr_add).next = &add;
return -1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T02:51:25.325Z | Question from Code | v1 | why am i getting a segmentation fault | 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 create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while(user_ptr_add != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
printf("%s", (**user_ptr_add).name);
return -1;
}
*user_ptr_add = (**user_ptr_add).next;
}
User add;
strcpy(add.name, name);
(*user_ptr_add)->next = &add;
return -1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T02:53:30.176Z | Question from Code | v1 | why am i getting a segmentation fault | 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 create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while(user_ptr_add != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
printf("%s", (**user_ptr_add).name);
return -1;
}
user_ptr_add = &(*user_ptr_add)->next;
}
User add;
strcpy(add.name, name);
(*user_ptr_add)->next = &add;
return -1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T02:55:56.404Z | Question from Code | v1 | why am i getting a segmentation fault | 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 create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while(user_ptr_add != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
return -1;
}
user_ptr_add = &((**user_ptr_add).next);
}
User add;
strcpy(add.name, name);
(**user_ptr_add).next = &add;
return -1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T03:07:18.280Z | Question from Code | v1 | why am i getting a segmentation fault | 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 create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while((*user_ptr_add)->next != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
return -1;
}
*user_ptr_add = (*user_ptr_add)->next;
}
User *add = malloc(sizeof(User));
strcpy(add->name, name);
(*user_ptr_add)->next = add;
return -1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T03:08:06.715Z | Question from Code | v1 | what line is causing a segmentation fault | 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 create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while((*user_ptr_add)->next != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
return -1;
}
*user_ptr_add = (*user_ptr_add)->next;
}
User *add = malloc(sizeof(User));
strcpy(add->name, name);
(*user_ptr_add)->next = add;
return -1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T03:09:06.707Z | Question from Code | v1 | how do i fix my segmentation fault | 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 create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while((*user_ptr_add)->next != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
return -1;
}
*user_ptr_add = (*user_ptr_add)->next;
}
User *add = malloc(sizeof(User));
strcpy(add->name, name);
(*user_ptr_add)->next = add;
return -1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T03:10:27.624Z | Question from Code | v1 | what line is causing a segmentation fault | 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 create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while((*user_ptr_add)->next != NULL && *user_ptr_add != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
return -1;
}
*user_ptr_add = (*user_ptr_add)->next;
}
User *add = malloc(sizeof(User));
strcpy(add->name, name);
(*user_ptr_add)->next = add;
return -1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T03:12:59.701Z | Question from Code | v1 | what line is causing a segmentation fault and how can i fix it | 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 create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > 33){
return -2;
}
while((*user_ptr_add)->next != NULL && *user_ptr_add != NULL){
if (strcmp((**user_ptr_add).name, name) == 0){
return -1;
}
*user_ptr_add = (*user_ptr_add)->next;
}
User *add = malloc(sizeof(User));
strcpy(add->name, name);
if((*user_ptr_add) == NULL){
user_ptr_add = &add;
}
else{
(*user_ptr_add)->next = add;
}
return 0;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T17:15:33.382Z | General Question | v1 | how to use fopen to see if a file exists | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T20:24:31.871Z | General Question | v1 | how to print an ascii file | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-02T20:48:20.230Z | Question from Code | v1 | why is there an infinite loop | User *find_user(const char *name, const User *head) {
User *curr = (User *)head;
while(curr != NULL){
if (strcmp(curr->name, name) == 0){
return curr;
}
}
return NULL;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-02-03T20:03:09.458Z | General Question | v1 | what does the time function do | null | null | null |
63c6481c5f004bf4898cf987 | 2023-02-05T01:04:02.208Z | Help Fix Code | v1 | null | typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post;
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 make_post(const User *author, User *target, char *contents) {
int i;
for(i = 0; i < MAX_FRIENDS; i++){
if((target->friends)[i] == author){
Post *pst = malloc(sizeof(Post));
strncpy(pst->author, author->name, MAX_NAME);
pst->contents = contents;
time_t now;
time(&now);
pst->date = &now;
pst->next = target->first_post;
target->first_post = pst;
}
}
return -1;
}
int print_user(const User *user) {
if (user == NULL){
return 1;
}
FILE *f = fopen(user->profile_pic, "r");
if(f != NULL){
char c = fgetc(f);
while(c != EOF){
printf("%c", c);
c = fgetc(f);
}
fclose(f);
}
printf("Name: %s\n", user->name);
printf("------------------------------------------\n");
printf("Friends:\n");
int i;
for(i = 0; i < MAX_FRIENDS; i++){
if(user->friends[i] != NULL){
printf("%s\n", user->friends[i]->name);
}
else{
break;
}
}
printf("------------------------------------------\n");
printf("Posts:\n");
Post *curr_post = user->first_post;
while(curr_post != NULL){
printf("From: %s\n", curr_post->author);
printf("%s\n", ctime(curr_post->date));
printf("\n");
printf("%s\n", curr_post->contents);
printf("\n");
curr_post = curr_post->next;
if(curr_post != NULL){
printf("===");
printf("\n");
}
}
printf("------------------------------------------\n");
return 0;
} | why is there a segmentation fault | null |
63c6481c5f004bf4898cf987 | 2023-02-05T02:33:57.526Z | Help Fix Code | v1 | null | typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post;
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 make_post(const User *author, User *target, char *contents) {
int i;
for(i = 0; i < MAX_FRIENDS; i++){
if((target->friends)[i] == author){
Post *pst = malloc(sizeof(Post));
strncpy(pst->author, author->name, MAX_NAME);
pst->contents = contents;
time_t now;
time(&now);
pst->date = &now;
pst->next = target->first_post;
target->first_post = pst;
}
}
return -1;
}
int create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > MAX_NAME){
return 2;
}
User *add = malloc(sizeof(User));
strcpy(add->name, name);
if(*user_ptr_add == NULL){
*user_ptr_add = add;
return 0;
}
User *curr = *user_ptr_add;
while(curr->next != NULL){
if (strcmp(curr->name, name) == 0){
return 1;
}
curr = curr->next;
}
if (strcmp(curr->name, name) != 0){
curr->next = add;
}
else{
return -1;
}
return 0;
}
int delete_user(const char *name, User **user_ptr_del) {
User *target = *user_ptr_del;
while(target != NULL){
if (strcmp(target->name, name) == 0){
int i;
for(i = 0; i < MAX_FRIENDS; i++){
User *curr_friend = target->friends[i];
int deleted = 0;
int j;
for(j = 0; j < (MAX_FRIENDS - 1); j++){
if(curr_friend->friends[j] == NULL){
break;
}
if (curr_friend->friends[j] == target || deleted == 1){
deleted = 1;
curr_friend->friends[j] = curr_friend->friends[j + 1];
}
}
curr_friend->friends[MAX_FRIENDS - 1] = NULL;
}
Post *curr_post = target->first_post;
while(curr_post != NULL){
free(curr_post->date);
}
free(target);
return 0;
}
target = target->next;
}
return 1;
} | why is there a segmentation fault | null |
63c6481c5f004bf4898cf987 | 2023-02-05T02:36:51.706Z | Question from Code | v1 | why is there a segmentation fault | typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post;
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 make_post(const User *author, User *target, char *contents) {
int i;
for(i = 0; i < MAX_FRIENDS; i++){
if((target->friends)[i] == author){
Post *pst = malloc(sizeof(Post));
strncpy(pst->author, author->name, MAX_NAME);
pst->contents = contents;
time_t now;
time(&now);
pst->date = &now;
pst->next = target->first_post;
target->first_post = pst;
}
}
return -1;
}
int create_user(const char *name, User **user_ptr_add) {
if(strlen(name) > MAX_NAME){
return 2;
}
User *add = malloc(sizeof(User));
strcpy(add->name, name);
if(*user_ptr_add == NULL){
*user_ptr_add = add;
return 0;
}
User *curr = *user_ptr_add;
while(curr->next != NULL){
if (strcmp(curr->name, name) == 0){
return 1;
}
curr = curr->next;
}
if (strcmp(curr->name, name) != 0){
curr->next = add;
}
else{
return -1;
}
return 0;
}
int delete_user(const char *name, User **user_ptr_del) {
User *target = *user_ptr_del;
while(target != NULL){
if (strcmp(target->name, name) == 0){
int i;
for(i = 0; i < MAX_FRIENDS; i++){
User *curr_friend = target->friends[i];
int deleted = 0;
int j;
for(j = 0; j < (MAX_FRIENDS - 1); j++){
if(curr_friend->friends[j] == NULL){
break;
}
if (curr_friend->friends[j] == target || deleted == 1){
deleted = 1;
curr_friend->friends[j] = curr_friend->friends[j + 1];
}
}
curr_friend->friends[MAX_FRIENDS - 1] = NULL;
}
Post *curr_post = target->first_post;
while(curr_post != NULL){
free(curr_post->contents);
free(curr_post->date);
}
free(target);
return 0;
}
target = target->next;
}
return 1;
} | null | null |
63c6481c5f004bf4898cf987 | 2023-03-12T20:45:21.323Z | General Question | v2 | how do u use st_mtim | null | null | null |
63c6481d5f004bf4898cf991 | 2023-01-19T03:20:34.165Z | General Question | v1 | Write a sample code for tim Sort using python | null | null | null |
63c6481e5f004bf4898cf99b | 2023-01-20T19:25:29.855Z | General Question | v1 | in c, how can i restrict scanf() to only read the first 10 characters inputed | null | null | null |
63c6481e5f004bf4898cf99b | 2023-01-20T19:27:05.980Z | General Question | v1 | what does char phone[11] mean? | null | null | null |
63c6481e5f004bf4898cf99b | 2023-01-27T00:49:51.605Z | Question from Code | v1 | is this an array or string | char file[31]; | null | null |
63c6481e5f004bf4898cf99b | 2023-01-27T00:51:06.079Z | Question from Code | v1 | is this valid in c? | char file;
file = '1234'; | null | null |
63c6481e5f004bf4898cf99b | 2023-01-27T00:51:29.880Z | Help Fix Code | v1 | null | char file;
file = '1234'; | file should be a string | null |
63c6481e5f004bf4898cf99b | 2023-01-29T01:37:19.216Z | General Question | v1 | in c, how can we read input from stand input in function main? | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-03T02:09:50.874Z | General Question | v1 | how can i concatenate a space to a string | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-10T20:18:07.258Z | General Question | v1 | how can i test if the pixels of a 24 bitmap is correctly printed out? | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-10T20:23:27.369Z | General Question | v1 | Any advices for aceing CSC209? | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-10T20:24:33.763Z | General Question | v1 | any recommendation for vs code studio c language configuration?
| null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-10T21:06:41.793Z | General Question | v1 | 'gcc' is not recognized as an internal or external command,
operable program or batch file. | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T01:02:11.326Z | General Question | v1 | how to use fprint to print time_t object | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T01:15:17.738Z | General Question | v1 | How can i print a file to standard output using fopen and fprintf | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T01:40:11.655Z | Question from Code | v1 | imagining we have a name1 and we call user1 = find_user(name1, hearder).given that this function returns NULL in this case, if i want to check user1 is not NULL in an if statement, how should i write it | /*
* Return a pointer to the user with this name in
* the list starting with head. Return NULL if no such user exists.
*
* NOTE: You'll likely need to cast a (const User *) to a (User *)
* to satisfy the prototype without warnings.
*/
User *find_user(const char *name, const User *head) {
// cast a (const User *) to a (User *)
User *current = (User *) head;
// Use a while loop chekc if there exists an user with this name in the list given
while (current != NULL){
if(strcmp(current->name, name)){
return current;
}
current = current -> next;
}
return NULL;
} | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T01:40:49.692Z | General Question | v1 | why do we use user1 insteand of *user1 | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T01:41:24.932Z | Question from Code | v1 | why we use user1 instead of *user1 | /*
* Return a pointer to the user with this name in
* the list starting with head. Return NULL if no such user exists.
*
* NOTE: You'll likely need to cast a (const User *) to a (User *)
* to satisfy the prototype without warnings.
*/
User *find_user(const char *name, const User *head) {
// cast a (const User *) to a (User *)
User *current = (User *) head;
// Use a while loop chekc if there exists an user with this name in the list given
while (current != NULL){
if(strcmp(current->name, name)){
return current;
}
current = current -> next;
}
return NULL;
} | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T01:42:38.315Z | General Question | v1 | why a pointer can be NULL | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T02:04:05.590Z | Question from Code | v1 | given that i have this function header, can i call this function with an argument of type User * instead of const User*? | User *find_user(const char *name, const User *head) { | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T02:04:41.208Z | Question from Code | v1 | what do you mean by const quanlifier is not part of the type? | User *find_user(const char *name, const User *head) { | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T02:09:12.160Z | Question from Code | v1 | How can I check if there is no empty place in friends? | 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 |
63c6481e5f004bf4898cf99b | 2023-02-13T03:24:15.399Z | General Question | v1 | how can i make a time_t object of current time | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T06:26:35.668Z | Help Fix 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;
new_user->next = malloc(sizeof(User));
| what is wrong with malloc here
| null |
63c6481e5f004bf4898cf99b | 2023-02-13T06:28:29.807Z | Help Fix 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;
new_user->next = malloc(sizeof(User*));
| the error says invalid conversion from void* to user* | null |
63c6481e5f004bf4898cf99b | 2023-02-13T06:29:28.114Z | Help Fix 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;
new_user->next = malloc(sizeof(User));
| avoid the error invalid conversion from void* to user*
and successfully allocate memory to this | null |
63c6481e5f004bf4898cf99b | 2023-02-13T06:36:14.777Z | Help Fix Code | v1 | null |
int create_user(const char *name, User **user_ptr_add) {
User *new_user;
new_user = malloc(sizeof(User));
User *current = *user_ptr_add;
// 2 if the name cannot fit in the name array (e.g. > MAX_NAME)
if (sizeof(name) > 31){
return 2;
}
// When this loop stops, current is the last pointer to User in user_ptr_add
while(current != NULL){
// return 1 user already exists in this list
if(strcmp(current->name, name) == 0){
return 1;
}
current = current->next;
}
// copy the name to new_user.name
strncpy(new_user->name, name, 32);
new_user->name[strlen(new_user->name)] = '\0';
// initialize this user's profile_pic to a null terminator
// (the first char in profile_pic)
new_user->profile_pic[0] = '\0';
// initialize other attributes
new_user->first_post = NULL;
for (int i = 0; i < MAX_FRIENDS; i++) {
new_user->friends[i] = malloc(sizeof(User)); //Allocate space of 1 User
new_user->friends[i] = NULL;
}
new_user->next = malloc(sizeof(User)); //Allocate space of 1 User
new_user->next = NULL;
// Add this new_user to the tail of user_prtr_add
current->next = new_user;
// return 0 if successful
return 0;
// Still need to free memory afterwards (!!!)
// Maybe everthing is freed through delete user
} | /*
* 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 |
63c6481e5f004bf4898cf99b | 2023-02-13T06:43:54.376Z | Question from Code | v1 | Do i need to actually use malloc for new_user->friends and new_user->next? |
int create_user(const char *name, User **user_ptr_add) {
User *new_user;
new_user = malloc(sizeof(User));
User *current = *user_ptr_add;
// 2 if the name cannot fit in the name array (e.g. > MAX_NAME)
if (sizeof(name) > 31){
return 2;
}
// When this loop stops, current is the last pointer to User in user_ptr_add
while(current != NULL){
// return 1 user already exists in this list
if(strcmp(current->name, name) == 0){
return 1;
}
current = current->next;
}
// copy the name to new_user.name
strncpy(new_user->name, name, 32);
new_user->name[strlen(new_user->name)] = '\0';
// initialize this user's profile_pic to a null terminator
// (the first char in profile_pic)
new_user->profile_pic[0] = '\0';
// initialize other attributes
new_user->first_post = NULL;
for (int i = 0; i < MAX_FRIENDS; i++) {
new_user->friends[i] = malloc(sizeof(User)); //Allocate space of 1 User
new_user->friends[i] = NULL;
}
new_user->next = malloc(sizeof(User)); //Allocate space of 1 User
new_user->next = NULL;
// Add this new_user to the tail of user_prtr_add
current->next = new_user;
// return 0 if successful
return 0;
// Still need to free memory afterwards (!!!)
// Maybe everthing is freed through delete user
} | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T06:44:32.177Z | Question from Code | v1 | Do i need to use malloc for new_user->friends and new_user->next which are attributes for new_user? |
int create_user(const char *name, User **user_ptr_add) {
User *new_user;
new_user = malloc(sizeof(User));
User *current = *user_ptr_add;
// 2 if the name cannot fit in the name array (e.g. > MAX_NAME)
if (sizeof(name) > 31){
return 2;
}
// When this loop stops, current is the last pointer to User in user_ptr_add
while(current != NULL){
// return 1 user already exists in this list
if(strcmp(current->name, name) == 0){
return 1;
}
current = current->next;
}
// copy the name to new_user.name
strncpy(new_user->name, name, 32);
new_user->name[strlen(new_user->name)] = '\0';
// initialize this user's profile_pic to a null terminator
// (the first char in profile_pic)
new_user->profile_pic[0] = '\0';
// initialize other attributes
new_user->first_post = NULL;
for (int i = 0; i < MAX_FRIENDS; i++) {
new_user->friends[i] = malloc(sizeof(User)); //Allocate space of 1 User
new_user->friends[i] = NULL;
}
new_user->next = malloc(sizeof(User)); //Allocate space of 1 User
new_user->next = NULL;
// Add this new_user to the tail of user_prtr_add
current->next = new_user;
// return 0 if successful
return 0;
// Still need to free memory afterwards (!!!)
// Maybe everthing is freed through delete user
} | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T06:45:46.177Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *new_user;
new_user = malloc(sizeof(User));
new_user->next = NULL;
new_user->first_post = NULL;
User *current = *user_ptr_add;
// retrun 2 if the name cannot fit in the name array (e.g. > MAX_NAME)
if (sizeof(name) > 31){
return 2;
}
// When this loop stops, current is the last pointer to User in user_ptr_add
while(current != NULL){
// return 1 user already exists in this list
if(strcmp(current->name, name) == 0){
return 1;
}
current = current->next;
}
// copy the name to new_user.name
strncpy(new_user->name, name, 32);
new_user->name[strlen(new_user->name)] = '\0';
// initialize this user's profile_pic to a null terminator
// (the first char in profile_pic)
new_user->profile_pic[0] = '\0';
// initialize other attributes
new_user->friends = malloc(sizeof(User) * 10);
for (int i = 0; i < MAX_FRIENDS; i++) {
new_user->friends[i] = NULL; //Allocate space of 1 User
}
new_user->next = malloc(sizeof(User)); //Allocate space of 1 User
new_user->next = NULL;
// Add this new_user to the tail of user_prtr_add
current->next = new_user;
// return 0 if successful
return 0;
} | /*
* 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 |
63c6481e5f004bf4898cf99b | 2023-02-13T19:51:36.357Z | General Question | v1 | given that i want to print to standardoutput, whats the difference between printf and fprintf | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T19:54:03.030Z | Question from Code | v1 | What the difference between these lines? which one should i use for reporting error | fprintf(stderr, "Error: could not open file or file does not exist");
printf("Error: could not open file or file does not exist"); | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T21:44:32.783Z | Question from Code | v1 | what is wrong with this code | User *find_user(const char *name, const User *head) {
// cast a (const User *) to a (User *)
User *current = (User *) head;
if (current == NULL)
{
return NULL;
}else if (strcmp(current->name, name))
{
return current;
}else{
if (current->next != NULL)
{
find_user(name, current->next);
}
}
} | null | null |
63c6481e5f004bf4898cf99b | 2023-02-13T21:45:22.883Z | Help Fix Code | v1 | null |
User *find_user(const char *name, const User *head) {
} | /*
* Return a pointer to the user with this name in
* the list starting with head. Return NULL if no such user exists.
*
* NOTE: You'll likely need to cast a (const User *) to a (User *)
* to satisfy the prototype without warnings.
*/ | null |
63c6481e5f004bf4898cf99b | 2023-02-13T21:52:27.386Z | Help Fix Code | v1 | null | User *find_user(const char *name, const User *head) {
// cast a (const User *) to a (User *)
User *current = (User *) head;
if (current == NULL)
{
return NULL;
}
while (current != NULL && current->next != NULL)
{
if(strcmp(current->name, name) == 0){
return current;
}
current = current->next;
}
return NULL;
} | /* * Return a pointer to the user with this name in * the list starting with head. Return NULL if no such user exists. * * NOTE: You'll likely need to cast a (const User *) to a (User *) * to satisfy the prototype without warnings. */ | null |
63c6481e5f004bf4898cf99b | 2023-02-14T01:00:28.281Z | Question from Code | v1 | gievn that current is assigned as in line 3. In the while loop, when I iterate using current. When i assign current in line 10, is there any changes made to user_ptr_add? | int create_user(const char *name, User **user_ptr_add) {
User *new_user = malloc(sizeof(User));
User *current = *user_ptr_add;
while(current != NULL && current->next != NULL){
// return 1 user already exists in this list
if(strcmp(current->name, name) == 0){
return 1;
}
current = current->next;
} | null | null |
63c6481e5f004bf4898cf99b | 2023-02-14T01:01:16.609Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *new_user = malloc(sizeof(User));
User *current = *user_ptr_add;
while(current != NULL && current->next != NULL){
// return 1 user already exists in this list
if(strcmp(current->name, name) == 0){
return 1;
}
current = current->next;
} | gievn that current is assigned as in line 3. In the while loop, when I iterate using current. When i assign current in line 10, I want this change to this object also cause changes to user_ptr_add, what should i do | null |
63c6481e5f004bf4898cf99b | 2023-02-14T01:02:16.066Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *new_user = malloc(sizeof(User));
User *current = *user_ptr_add;
while(current != NULL && current->next != NULL){
// return 1 user already exists in this list
if(strcmp(current->name, name) == 0){
return 1;
}
current = current->next;
}
current->next = new_user; | gievn that current is assigned as in line 3. In the while loop, when I iterate using current. When i assign current in line 13, I want this change to this object also cause changes to user_ptr_add, what should i do | null |
63c6481e5f004bf4898cf99b | 2023-02-14T07:02:46.296Z | General Question | v1 | Program received signal SIGSEGV, Segmentation fault.
__GI_localtime (t=0x63eb26af) at ./time/localtime.c:54
i get this error, how can i solve it | null | null | null |
63c6481e5f004bf4898cf99b | 2023-02-14T07:06:02.664Z | Question from Code | v1 | I have this struct post, when I allocate memory as in line 8, does that means I've also allocated memory to new_post->contents and date? | typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post;
Post *new_post = malloc(sizeof(Post)); | null | null |
63c6481e5f004bf4898cf99b | 2023-02-14T07:07:05.485Z | Question from Code | v1 | I have this struct user, when I allocate memory as in line 8, does that means I've also allocated memory to user->first_post and etc? | typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends[MAX_FRIENDS];
struct user *next;
} User;
User *user = malloc(sizeof(User)); | null | null |
63c6481e5f004bf4898cf99b | 2023-02-14T07:07:48.827Z | Question from Code | v1 | how can i properly allocate memory to user object and all of its attributes? | typedef struct user {
char name[MAX_NAME];
char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents.
struct post *first_post;
struct user *friends[MAX_FRIENDS];
struct user *next;
} User;
User *user = malloc(sizeof(User)); | null | null |
63c6481e5f004bf4898cf99b | 2023-02-14T07:23:16.568Z | Help Fix Code | v1 | null | void list_posts(const Post *curr) {
// cast a (const Post *) to a (Post *)
Post *current = (Post *) curr;
while (current != NULL){
// print to standard output
printf("From: %s\n", current->author);
printf("Date: %s\n", ctime(current->date));
printf("%s\n", current->contents);
if (current->next != NULL)
{
printf("\n");
printf("===\n");
printf("\n");
}
current = current->next;
}
} | this code is causing segmentation fault with ./time/localtime.c: No such file or directory.
how can i fix it? | null |
63c6481e5f004bf4898cf99b | 2023-02-14T07:24:03.685Z | Help Fix Code | v1 | null | typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post;
void list_posts(const Post *curr) {
// cast a (const Post *) to a (Post *)
Post *current = (Post *) curr;
while (current != NULL){
// print to standard output
printf("From: %s\n", current->author);
printf("Date: %s\n", ctime(current->date));
printf("%s\n", current->contents);
if (current->next != NULL)
{
printf("\n");
printf("===\n");
printf("\n");
}
current = current->next;
}
} | this code is causing segmentation fault with ./time/localtime.c: No such file or directory. how can i fix it? | null |
63c6481e5f004bf4898cf99b | 2023-02-14T21:46:30.473Z | Help Fix 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;
typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post;
int delete_user(const char *name, User **user_ptr_del) {
// the first user in this list
User *current_user = *user_ptr_del;
User *prev = NULL;
User *found_user = NULL;
while (current_user != NULL)
{
if (strcmp(name, current_user->name) == 0)
{
found_user = current_user;
break;
}
prev = current_user;
current_user = current_user->next;
}
// return 1 of a user with this name does not exist
if (found_user == NULL)
{
return 1;
}else{
// make the next of prev be the next of found_user
prev->next = found_user->next;
}
// free user's posts list
// free_users_post_list(found_user->first_post);
// free each friend
for (int i = 0; i < MAX_FRIENDS; i++) {
if (found_user->friends[i] == NULL) {
break;
}
// remove the deleted user from friend list of this friend
for (int j = 0; j < MAX_FRIENDS; j++) {
// free post from this user in friends' post lists
free_post_from_author(name, found_user->friends[i]);
if (strcmp((char *)(found_user->friends)[i]->friends[j]->name, name) == 0)
{
found_user->friends[i]->friends[j - 1]->next = found_user->friends[i]->friends[j + 1];
}
}
}
free(found_user->friends);
// free the user
free(found_user);
// return 0 on success
return 0;
} | in the function delete_user strcmp in line 57 is causing segmentation fault | null |
63c6481e5f004bf4898cf99b | 2023-02-17T00:09:07.074Z | Help Fix Code | v1 | null | char *copy(char *dest, const char *src, int capacity) {
int i;
for (i = 0; i < capacity && src[i] != '\0'; i++){
dest[i] = src[i];
}
for (int j = i; j < capacity; j++)
{
dest[i] = '\0';
}
// explicitly make dest null-terminated when there is no null terminator in
// the first 'capacity' chars in src.
dest[sizeof(dest) - 1] = '\0';
return dest;
} | /* 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.
*/ | null |
63c6481e5f004bf4898cf99b | 2023-03-13T06:21:02.635Z | Help Fix Code | v2 | in line 11, buffer_line should be assigend to "main : linked_list.o main.o". Suppose we the ngoes into line 18. in line 28, the buffer_line in parse_target_dependency should be "main : linked_list.o main.o", but it turns out to be "main" which is wrong | /* Read from the open file fp, and create the linked data structure
that represents the Makefile contained in the file.
See the top of pmake.h for the specification of Makefile contents.
*/
Rule *parse_file(FILE *fp) {
// Implement this function and remove the stubbed return statement below.
char buffer_line[MAXLINE];
Rule* first_rule_ptr = NULL;
Rule *current_rule = NULL;
while (fgets(buffer_line, MAXLINE, fp) != NULL){
// buffer_line[MAXLINE - 1] = '\0';
// If the line is a comment line
if (is_comment_or_empty(buffer_line)){
continue;
}
// If the line is a target line
else if (buffer_line[0] != '\t'){
char buffer_copy[MAXLINE];
strcpy(buffer_copy, buffer_line);
// Parse target and dependencies
if (first_rule_ptr == NULL){
char *token = strtok(buffer_line, " ");
first_rule_ptr = init_rule(token);
current_rule = first_rule_ptr;
}
Rule *this_rule = parse_target_dependency(buffer_copy, first_rule_ptr);
Action *first_action;
Action *current_action = NULL;
// Parse Actions
while (fgets(buffer_line, MAXLINE, fp) != NULL && buffer_line[0] == '\t')
{
Action *new_action = parse_action_line(buffer_line);
// If the linked list of action nodes is empty
if (current_action == NULL)
{
first_action = new_action;
current_action = new_action;
}else{
current_action->next_act = new_action;
current_action = current_action->next_act;
}
}
this_rule->actions = first_action;
current_rule->next_rule = this_rule;
current_rule = current_rule->next_rule;
}
}
return first_rule_ptr;
} | null | null |
63c6481e5f004bf4898cf99b | 2023-03-13T06:57:44.878Z | Help Fix Code | v2 | given that MAXLINE = 256. fgets on line 7 is reading too much than expected. for a line "main : linked_list.o main.o\n" it should only read "main : linked_list.o main.o" but its giving garbage after that | Rule *parse_file(FILE *fp) {
// Implement this function and remove the stubbed return statement below.
char buffer_line[MAXLINE];
Rule* first_rule_ptr = NULL;
Rule *current_rule = NULL;
//fgets(buffer_line, MAXLINE, fp)
while (fgets(buffer_line, MAXLINE, fp)){
..... | null | null |
63c6481e5f004bf4898cf99b | 2023-03-13T20:06:02.518Z | Help Fix Code | v2 | the line parameter given will be a string start with a tab. I want to store every word (splited by space) except the tab to a char **
| Action *parse_action_line(char line[MAXLINE]){
int max_strings = MAXLINE/2;
char **args_array = malloc(max_strings * sizeof(char *));
char *delim = "\t";
// Gives the string before "\t" which is empty.
char *token = strtok(line, delim);
// Gives the string before " " and after "\t"
token = strtok(NULL, " ");
int i = 0;
while (token != NULL)
{
args_array[i] = strdup(token);
token = strtok(NULL, " ");
i++;
}
// Last element in Action->args is NULL.
args_array[i] = NULL;
Action *new_action = malloc(sizeof(Action));
new_action->args = args_array;
new_action->next_act = NULL;
return new_action;
} | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-06T19:09:11.620Z | General Question | v1 | how to check malloc fail | null | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-06T19:15:57.910Z | General Question | v1 | how to check two strings are equal | null | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-06T19:18:27.791Z | General Question | v1 | default value of declared variable | null | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-06T19:20:01.377Z | General Question | v1 | how to check for empty array | null | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-06T19:24:49.002Z | General Question | v1 | how to check if reach end of array | null | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-06T19:31:08.927Z | General Question | v1 | explain how linked list is implemented in c | null | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-08T22:26:02.566Z | General Question | v1 | is const char always a proper string | null | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-08T22:26:32.939Z | General Question | v1 | is const char* always a proper string | null | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-08T22:27:23.213Z | General Question | v1 | can I only use strlen on proper string | null | null | null |
63c6481e5f004bf4898cf9a0 | 2023-02-08T22:45:05.554Z | General Question | v1 | how to check two strings are equal | null | null | null |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.