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
⌀ |
---|---|---|---|---|---|---|---|
63c647f35f004bf4898cf81a
|
2023-02-01T21:12:26.408Z
|
General Question
|
v1
|
How to reassign a string literal?
| null | null | null |
63c647f35f004bf4898cf81a
|
2023-02-01T21:16:55.709Z
|
Help Fix Code
|
v1
| null |
int truncate(char *s, int n){
char *s_copy = malloc(sizeof(char) * strlen(s) + 1);
strcpy(s_copy, s);
int l = (int)strlen(s);
int res = 0;
if(strlen(s) > n){
s_copy[n] = '\0';
s = s_copy;
res = l - n;
}
return res;
}
|
how can I change the s outside of the function?
| null |
63c647f35f004bf4898cf81a
|
2023-02-15T19:44:20.302Z
|
Help Fix Code
|
v1
| null |
int create_user(const char *name, User **user_ptr_add) {
User *curr = *user_ptr_add;
int res = 0;
/*Check whether the user name already exists in the list
*/
while (curr->next){
if (curr->name == name){
res = 1;
}
curr = curr->next;
}
if (res == 1){
return res;
}
/*Check whether the given name cannot fit in the 'name' array
*/
if (strlen(name) > MAX_NAME - 1){
return 2;
}
/*Create the user with name
*/
User u1;
strcpy(u1.name,name);
curr->next = &u1;
return 0;
}
|
how to solve the segmentation fault.
| null |
63c647f35f004bf4898cf81a
|
2023-02-15T19:46:58.434Z
|
Help Fix Code
|
v1
| null |
int create_user(const char *name, User **user_ptr_add) {
/*Check whether the user name already exists in the list
*/
User *curr1 = *user_ptr_add;
User curr = *curr1;
int res = 0;
while (curr.next){
if (strcmp(curr.name, name) == 0){
res = 1;
}
curr = *curr.next;
}
if (res == 1){
return res;
}
/*Check whether the given name cannot fit in the 'name' array
*/
if (strlen(name) > MAX_NAME - 1){
return 2;
}
/*Create the user with name
*/
User *u1ptr = malloc(sizeof(User));
User u1 = *u1ptr;
strcpy(u1.name,name);
for (int i =0; i <10; i++){
u1.friends[i] = NULL;
}
u1.next = NULL;
u1.first_post = NULL;
strcpy(u1.profile_pic,"");
curr.next = u1ptr;
return 0;
}
|
how to solve the segmentation fault.
| null |
63c647f35f004bf4898cf81a
|
2023-02-15T19:52:45.958Z
|
Help Fix Code
|
v1
| null |
int create_user(const char *name, User **user_ptr_add) {
User *curr = *user_ptr_add;
int res = 0;
while (curr->next){
if (strcmp(curr->name, name) == 0){
res = 1;
}
curr = curr->next;
}
if (res == 1){
return res;
}
if (strlen(name) > MAX_NAME - 1){
return 2;
}
User *u1ptr = malloc(sizeof(User));
strcpy(u1ptr->name,name);
for (int i =0; i <10; i++){
u1ptr->friends[i] = NULL;
}
u1ptr->next = NULL;
u1ptr->first_post = NULL;
strcpy(u1ptr->profile_pic,"");
curr->next = u1ptr;
return 0;
}
|
how to solve the segmentation fault.
| null |
63c647f35f004bf4898cf81a
|
2023-02-15T20:00:16.671Z
|
Question from Code
|
v1
|
how to fix the segmentation fault?
|
int create_user(const char *name, User **user_ptr_add) {
User *curr = *user_ptr_add;
int res = 0;
while (curr->next){
if (strcmp(curr->name, name) == 0){
res = 1;
}
curr = curr->next;
}
if (res == 1){
return res;
}
if (strlen(name) > MAX_NAME - 1){
return 2;
}
User *u1ptr = malloc(sizeof(User));
strcpy(u1ptr->name,name);
for (int i =0; i <10; i++){
u1ptr->friends[i] = NULL;
}
u1ptr->next = NULL;
u1ptr->first_post = NULL;
strcpy(u1ptr->profile_pic,"");
curr->next = u1ptr;
return 0;
}
| null | null |
63c647f35f004bf4898cf81a
|
2023-02-15T20:26:33.255Z
|
Help Fix Code
|
v1
| null |
int create_user(const char *name, User **user_ptr_add) {
/*Check whether the user name already exists in the list
*/
User *curr = *user_ptr_add;
int res = 0;
while (curr->next){
if (strcmp(curr->name, name) == 0){
res = 1;
}
curr = curr->next;
}
if (res == 1){
return res;
}
/*Check whether the given name cannot fit in the 'name' array
*/
if (strlen(name) > MAX_NAME - 1){
return 2;
}
/*Create the user with name
*/
User *u1ptr = malloc(sizeof(User));
strcpy(u1ptr->name,name);
for (int i =0; i <10; i++){
u1ptr->friends[i] = NULL;
}
u1ptr->next = NULL;
u1ptr->first_post = NULL;
strcpy(u1ptr->profile_pic,"");
curr->next = u1ptr;
return 0;
}
|
how to fix the segmentation fault?
| null |
63c647f35f004bf4898cf81a
|
2023-02-15T20:27:19.204Z
|
Question from Code
|
v1
|
How to solvr fault?
|
int create_user(const char *name, User **user_ptr_add) {
/*Check whether the user name already exists in the list
*/
User *curr = *user_ptr_add;
int res = 0;
while (curr->next){
if (strcmp(curr->name, name) == 0){
res = 1;
}
curr = curr->next;
}
if (res == 1){
return res;
}
/*Check whether the given name cannot fit in the 'name' array
*/
if (strlen(name) > MAX_NAME - 1){
return 2;
}
/*Create the user with name
*/
User *u1ptr = malloc(sizeof(User));
strcpy(u1ptr->name,name);
for (int i =0; i <10; i++){
u1ptr->friends[i] = NULL;
}
u1ptr->next = NULL;
u1ptr->first_post = NULL;
strcpy(u1ptr->profile_pic,"");
curr->next = u1ptr;
return 0;
}
| null | null |
63c647f35f004bf4898cf81a
|
2023-02-15T20:29:40.641Z
|
Question from Code
|
v1
|
Is there any issues?
|
int check_friends(User *user1, User *user2){
for(int i = 0; i < 10; i++){
if(user1->friends[i]){
if(user1->friends[i]->name == user2->name){
return 0;
}
}
}
return 1;
}
| null | null |
63c647f35f004bf4898cf81a
|
2023-02-15T23:52:09.449Z
|
Help Fix Code
|
v1
| null |
char str[1000];
FILE *fptr;
fptr = fopen(user->profile_pic,"r");
if(fptr != NULL){
if(fgets(str, 1000, fptr) != NULL){
printf("%s",str);
}
}
|
How to fix segmentation fault?
| null |
63c647f35f004bf4898cf81a
|
2023-02-15T23:53:02.065Z
|
Help Fix Code
|
v1
| null |
char str[1000];
FILE *fptr;
fptr = fopen(user->profile_pic,"r");
if(fptr != NULL){
if(fgets(str, 1000, fptr) != NULL){
printf("%s",str);
}
}
fclose(fptr);
|
How to fix segmentation fault?
| null |
63c647f35f004bf4898cf81a
|
2023-02-15T23:54:29.673Z
|
Explain Code
|
v1
| null |
char str[1000];
FILE *fptr;
fptr = fopen(user->profile_pic,"r");
if(fptr != NULL){
if(fgets(str, 1000, fptr) != NULL){
printf("%s",str);
fclose(fptr);
}
}
| null | null |
63c647f55f004bf4898cf829
|
2023-01-29T01:08:20.639Z
|
General Question
|
v1
|
how can i check how many digits an integer has in c
| null | null | null |
63c647f55f004bf4898cf829
|
2023-01-29T21:42:33.916Z
|
General Question
|
v1
|
what kind of info does ls -l give
| null | null | null |
63c647f55f004bf4898cf829
|
2023-01-29T23:02:27.347Z
|
General Question
|
v1
|
why am i failing the sanity check
| null | null | null |
63c647f55f004bf4898cf829
|
2023-01-29T23:44:20.857Z
|
Help Fix Code
|
v1
| null |
#include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
//int check_permissions(char *, char *);
int check_permissions(char *given_perms, char *req_perms){
for(int i = 0; i < 9; i++){
if (req_perms[i]!='-'){
if(given_perms[i]!=req_perms[i]){
return 1;
}
}
}
return 0;
}
int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
else{
int count = 0;
// TODO: Process command line arguments.
char total[5];
int totalnum;
scanf("%s %d\n", total, &totalnum);
char filetype;
char perms[9];
int misc0;
char misc1[31];
char misc2[31];
int size;
char month[31];
int day;
char time[5];
char name[31];
while(scanf("%c%s %d %s %s %d %s %d %s %s\n", &filetype, perms, &misc0, misc1, misc2, &size, month, &day, time, name)==10){
// checking size of file is big enough
int req_size = atoi(argv[0]);
if(size > req_size && filetype != 'd'){
//checking file is not a directory
//checking required permissions, if applicable
if (argc==2){
count = count + 1;
}
// TODO: Call check_permissions as part of your solution to count the files to compute and print the correct value.
else if(argc==3 && check_permissions(perms, argv[2])==0){
count = count + 1;
}
else{
count = count + 0;
}
}
}
printf("%d\n", count);
return 0;
}
}
|
reasons for sanity check fail
| null |
63c647f55f004bf4898cf829
|
2023-01-29T23:47:35.025Z
|
Help Fix Code
|
v1
| null |
#include <stdio.h>
#include <stdlib.h>
// TODO: Implement a helper named check_permissions that matches the prototype below.
//int check_permissions(char *, char *);
int check_permissions(char *given_perms, char *req_perms){
for(int i = 0; i < 9; i++){
if (req_perms[i]!='-'){
if(given_perms[i]!=req_perms[i]){
return 1;
}
}
}
return 0;
}
int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
else{
int count = 0;
// TODO: Process command line arguments.
char total[5];
int totalnum;
scanf("%s %d\n", total, &totalnum);
char filetype;
char perms[9];
int misc0;
char misc1[31];
char misc2[31];
int size;
char month[31];
int day;
char time[5];
char name[31];
while(scanf("%c%s %d %s %s %d %s %d %s %s\n", &filetype, perms, &misc0, misc1, misc2, &size, month, &day, time, name)==10){
// checking size of file is big enough
int req_size = atoi(argv[1]);
if(size > req_size && filetype != 'd'){
//checking file is not a directory
//checking required permissions, if applicable
if (argc==2){
count = count + 1;
}
// TODO: Call check_permissions as part of your solution to count the files to compute and print the correct value.
else if(argc==3 && check_permissions(perms, argv[2])==0){
count = count + 1;
}
else{
count = count + 0;
}
}
}
printf("%d\n", count);
return 0;
}
}
|
read from a file
| null |
63c647f55f004bf4898cf829
|
2023-02-15T16:37:51.021Z
|
General Question
|
v1
|
how can i cast a (const User *) to a (User *)
| null | null | null |
63c647f55f004bf4898cf829
|
2023-02-15T16:38:33.094Z
|
General Question
|
v1
|
what is a const
| null | null | null |
63c647f55f004bf4898cf829
|
2023-02-15T16:40:35.031Z
|
General Question
|
v1
|
how do linked lists work in c
| null | null | null |
63c647f55f004bf4898cf829
|
2023-02-15T18:01:52.279Z
|
General Question
|
v1
|
how can i print a text file to standard output
| null | null | null |
63c647f55f004bf4898cf829
|
2023-02-15T19:03:15.270Z
|
Help Fix Code
|
v1
| null |
#include "friends.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/*
* 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)
*/
int create_user(const char *name, User **user_ptr_add) {
if(find_user(name, *user_ptr_add) != NULL){
return 1;
}
else if(strlen(name) >= MAX_NAME){
return 2;
}
else{
User *curr = *user_ptr_add;
while(curr->next != NULL){
curr = curr->next;
}
User *new_user = malloc(sizeof(User));
if(new_user==NULL){
exit(1);
}
strcpy(new_user->name, name);
strcpy(new_user->profile_pic, "");
new_user->first_post = NULL;
for (int i = 0; i < MAX_FRIENDS; i++) {
new_user->friends[i] = NULL;
}
new_user->next = NULL;
curr->next = new_user;
return 0;
}
}
/*
* 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) {
while (head != NULL) {
if (strcmp(head->name, name) == 0){
return (User *)head;
}
head = head->next;
}
return 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) {
printf("User List\n");
while(curr->next != NULL){
printf(" %s\n", curr->name);
curr = curr->next;
}
}
/*
* Change the filename for the profile pic of the given user.
*
* Return:
* - 0 on success.
* - 1 if the file does not exist or cannot be opened.
* - 2 if the filename is too long.
*/
int update_pic(User *user, const char *filename) {
FILE *file = fopen(filename, "r");
int return_val;
if (file == NULL) {
return_val = 1;
}
else if(strlen(filename) >= MAX_NAME){
return_val = 2;
}
else{
return_val = 0;
strcpy(user->profile_pic, filename);
}
fclose(file);
return return_val;
}
/*
* Make two users friends with each other. This is symmetric - a pointer to
* each user must be stored in the 'friends' array of the other.
*
* New friends must be added in the first empty spot in the 'friends' array.
*
* Return:
* - 0 on success.
* - 1 if the two users are already friends.
* - 2 if the users are not already friends, but at least one already has
* MAX_FRIENDS friends.
* - 3 if the same user is passed in twice.
* - 4 if at least one user does not exist.
*
* Do not modify either user if the result is a failure.
* NOTE: If multiple errors apply, return the *largest* error code that applies.
*/
int make_friends(const char *name1, const char *name2, User *head) {
if((find_user(name1, head) == NULL) || (find_user(name2, head) == NULL)){
return 4;
}
else if(strcmp(name1, name2) == 0){
return 3;
}
else{
User *user1 = find_user(name1, head);
User *user2 = find_user(name2, head);
int existing_name_count = 0;
int friends1_size = 0;
int friends2_size = 0;
//checking friends list
for(int i = 0; i < MAX_FRIENDS; i++){
if((strcmp(user1->friends[i]->name, name2) == 0) || (strcmp(user2->friends[i]->name, name1) == 0)){
existing_name_count = existing_name_count + 1;
}
if(user1->friends[i] != NULL){
friends1_size = friends1_size + 1;
}
if(user2->friends[i] != NULL){
friends2_size = friends2_size + 1;
}
}
if(existing_name_count == 0){
if((friends1_size == MAX_FRIENDS) || (friends2_size == MAX_FRIENDS)){
return 2;
}
else{
user1->friends[friends1_size] = user2;
user2->friends[friends2_size] = user1;
return 0;
}
}
else{
return 1;
}
}
return -1;
}
/*
* Print a user profile.
* For an example of the required output format, see the example output
* linked from the handout.
* Return:
* - 0 on success.
* - 1 if the user is NULL.
*/
int print_user(const User *user) {
if(user == NULL){
return 1;
}
else{
//Printing profile picture
FILE *file = fopen(user->profile_pic, "r");
if(file!=NULL){
char line[500];
while (fgets(line, sizeof(line), file)) {
printf("%s", line);
}
}
fclose(file);
//Printing name
printf("%s %s\n%s\n", "Name: ", user->name, "------------------------------------------");
//Printing friends
printf("%s\n", "Friends:");
int i = 0;
while(user->friends[i] != NULL){
printf("%s\n", user->friends[i]->name);
}
printf("%s\n", "------------------------------------------");
//Printing posts
printf("%s\n", "Posts:");
Post *curr_post = user->first_post;
while(curr_post != NULL){
printf("%s%s\n", "From: ", curr_post->author);
printf("%s%s\n", "Date: ", ctime(curr_post->date));
printf("\n%s\n", curr_post->contents);
if(curr_post->next != NULL){
printf("\n===\n\n");
}
curr_post = curr_post->next;
}
printf("%s\n", "------------------------------------------");
}
return -1;
}
/*
* Make a new post from 'author' to the 'target' user,
* containing the given contents, IF the users are friends.
*
* Insert the new post at the *front* of the user's list of posts.
*
* 'contents' is a pointer to heap-allocated memory - you do not need
* to allocate more memory to store the contents of the post.
*
* Return:
* - 0 on success
* - 1 if users exist but are not friends
* - 2 if either User pointer is NULL
*/
int make_post(const User *author, User *target, char *contents) {
if((author == NULL) || (target == NULL)){
return 2;
}
else{
//Checking for friendship
int friends = 0;
for(int i = 0; i < MAX_FRIENDS; i++){
if((strcmp(author->friends[i]->name, target->name) == 0) || (strcmp(target->friends[i]->name, author->name) == 0)){
friends = friends + 1;
}
}
// they are friends
if(friends > 0){
Post *new_post = malloc(sizeof(Post));
if(new_post == NULL){
exit(1);
}
strcpy(new_post->author, author->name);
new_post->contents = contents;
time(new_post->date);
new_post->next = target->first_post;
target->first_post = new_post;
return 0;
}
// not friends
else{
return 1;
}
}
}
/*
* From the list pointed to by *user_ptr_del, delete the user
* with the given name.
* Remove the deleted user from any lists of friends.
*
* Return:
* - 0 on success.
* - 1 if a user with this name does not exist.
*/
int delete_user(const char *name, User **user_ptr_del) {
if(find_user(name, *user_ptr_del) == NULL){
return 1;
}
else{
User *user = find_user(name, *user_ptr_del);
//removing target from list of users
User *curr = *user_ptr_del;
User *curr2 = *user_ptr_del;
User *prev_from_target;
User *target;
while(curr!=NULL){
if(strcmp(curr->next->name, name)==0){
prev_from_target = curr;
target = curr->next;
}
curr = curr->next;
}
prev_from_target->next = target->next;
target->next = NULL;
//removing target from list of friends
while(curr2!=NULL){
for(int i = 0; i < MAX_FRIENDS; i++){
//user in friends list
if(strcmp(curr2->friends[i]->name,name)==0){
//shifting down friends list to overlap/delete the target user
for(int j = i; i < (MAX_FRIENDS - 1); j++){
curr2->friends[j] = curr2->friends[j + 1];
}
curr2->friends[MAX_FRIENDS - 1] = NULL;
}
}
curr2 = curr2->next;
}
//freeing dynamically allocated memory
free(user);
Post *curr_post = user->first_post;
while(curr_post!=NULL){
free(curr_post);
curr_post = curr_post->next;
}
return 0;
}
}
|
adding david to users
| null |
63c647f55f004bf4898cf829
|
2023-03-03T18:04:12.179Z
|
Help Fix Code
|
v1
| null |
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: forkloop <iterations>\n");
exit(1);
}
int iterations = strtol(argv[1], NULL, 10);
int child_num = 0;
for (int i = 0; i < iterations; i++) {
int n = fork();
if (n == 0) {
if (child_num < iterations) {
child_num++;
}
exit(0);
}
if (n < 0) {
perror("fork");
exit(1);
}
printf("ppid = %d, pid = %d, i = %d\n", getppid(), getpid(), i);
}
return 0;
}
|
each child process needs to have a different id
| null |
63c647f55f004bf4898cf829
|
2023-03-16T01:03:54.557Z
|
General Question
|
v2
|
how can i check if a struct is null
| null | null | null |
63c647f55f004bf4898cf829
|
2023-03-16T01:25:34.889Z
|
Help Write Code
|
v2
| null | null | null |
create a linkedlist structure that keeps track of names
|
63c647f55f004bf4898cf829
|
2023-03-16T01:40:05.175Z
|
Help Write Code
|
v2
| null | null | null |
check that a line starts with a tab
|
63c647f55f004bf4898cf829
|
2023-03-16T02:37:14.360Z
|
Help Fix Code
|
v2
|
change this to strncpy
|
strcpy(copied_action_line, action_line);
| null | null |
63c647f55f004bf4898cf82e
|
2023-01-31T20:56:47.642Z
|
Question from Code
|
v1
|
difference between string literal and string
|
char *s = "hi";
char s[] = "hi";
| null | null |
63c647f55f004bf4898cf82e
|
2023-01-31T21:00:41.860Z
|
Question from Code
|
v1
|
what is y
|
char *s = "hi";
char x = "hello"
char **y = &x;
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-14T19:34:50.095Z
|
Question from Code
|
v1
|
what is 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 |
63c647f55f004bf4898cf82e
|
2023-02-14T19:36:22.096Z
|
General Question
|
v1
|
what is the initial value of a string
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-14T19:37:10.788Z
|
General Question
|
v1
|
what is null character
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-14T19:38:02.480Z
|
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 |
63c647f55f004bf4898cf82e
|
2023-02-14T19:55:35.660Z
|
Question from Code
|
v1
|
what is the initial value of firends
|
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 |
63c647f55f004bf4898cf82e
|
2023-02-14T22:06:02.754Z
|
Explain Code
|
v1
| null |
int i, j = 0;
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-14T22:06:39.172Z
|
Explain Code
|
v1
| null |
int i, j = 0, 0;
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-14T22:15:33.316Z
|
General Question
|
v1
|
What is the pointer that point to NULL
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-14T22:18:14.597Z
|
Question from Code
|
v1
|
is p 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;
User u;
u = NULL;
User *p = &u;
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-14T22:20:03.453Z
|
General Question
|
v1
|
how to figure out a pointer is pointing to NULL?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-14T22:44:50.210Z
|
Explain Code
|
v1
| null |
char s[10];
s = NULL;
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T01:44:16.723Z
|
General Question
|
v1
|
what does the function time() do?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T01:44:56.452Z
|
General Question
|
v1
|
what does the function ctime() do?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T01:47:15.464Z
|
General Question
|
v1
|
what is the arguments of function time()
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T02:18:12.311Z
|
Question from Code
|
v1
|
what will User->next->name be?
|
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 |
63c647f55f004bf4898cf82e
|
2023-02-15T13:17:03.039Z
|
General Question
|
v1
|
what is the argument of free()
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T13:17:33.428Z
|
General Question
|
v1
|
Is string a pointer?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T13:23:45.161Z
|
General Question
|
v1
|
If the first part of and is False, will it check the second part of and?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T13:24:20.352Z
|
General Question
|
v1
|
what is and symbol
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T13:24:46.702Z
|
General Question
|
v1
|
Difference between & and &&
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T13:28:05.161Z
|
General Question
|
v1
|
How to remove an element in an array
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T13:32:39.001Z
|
Question from Code
|
v1
|
what will i[2] be?
|
int i[2];
i[0] = 1;
i[1] = 2;
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T14:33:56.727Z
|
General Question
|
v1
|
What is the argument of ctime()
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T14:44:01.883Z
|
Question from Code
|
v1
|
can I set u.profile_pic to 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;
User u;
u.profile_pic = NULL;
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T14:46:29.919Z
|
Question from Code
|
v1
|
what is the initial value of profile_pic?
|
char profile_pic[32]
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T14:47:14.253Z
|
Question from Code
|
v1
|
what is the value of profile_pic?
|
char profile_pic[32]
profile_pic[0] = '\0'
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T14:49:04.067Z
|
General Question
|
v1
|
Can I set a variable contains a struct to NULL?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T14:51:58.958Z
|
Question from Code
|
v1
|
what is the value of empty_friends?
|
#define MAX_NAME 32 // Max username and profile_pic filename lengths
#define MAX_FRIENDS 10 // Max number of friends a user can have
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 *empty_friends[MAX_FRIENDS];
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T16:00:41.383Z
|
General Question
|
v1
|
how to assign to expression with array
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T16:02:02.121Z
|
General Question
|
v1
|
When I create an object of a struct, will the values in the struct be created automatically?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T16:06:47.083Z
|
General Question
|
v1
|
how to assign an array to the attributes of a struct
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T16:07:45.641Z
|
General Question
|
v1
|
how to assign variable with array
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T16:39:03.979Z
|
Explain Code
|
v1
| null |
int create_user(const char *name, User **user_ptr_add) {
//check whether the name is too long;
if (strlen(name) > MAX_NAME - 1){
return 2;
}
//check whether the user already exists and find the previous user of new user
User *curr = *user_ptr_add;
while (curr->next != NULL){
if (strcmp(curr->name, name) == 0){
return 1;
}
curr = curr->next;
}
//create new user
User new_user;
strcpy(new_user.name, name);
char profile[MAX_NAME];
profile[0] = '\0';
strcpy(new_user.profile_pic, profile);
new_user.first_post = NULL;
for (int i = 0; i < MAX_FRIENDS; i++){
new_user.friends[i] = NULL;
}
new_user.next = NULL;
//put the new_user in the list
curr->next = &new_user;
return 0;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T20:26:05.428Z
|
General Question
|
v1
|
what is the difference between ptr = &value and *ptr = value?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T23:17:16.406Z
|
Question from Code
|
v1
|
does line 15 work?
|
typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post;
int main(){
time_t date;
time(&date);
Post *ptr;
ptr = malloc(sizeof(Post));
strcpy(ptr->author, author->name);
strcpy(ptr->contents, contents);
ptr->date = &date;
ptr->next = NULL;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T23:20:39.442Z
|
General Question
|
v1
|
if I want to assign value to a string literal which is a variable of a struct, what should I do?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T23:23:03.111Z
|
Question from Code
|
v1
|
what segmentation fault the code may cause?
|
typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post;
int main(){
time_t date;
time(&date);
Post *ptr;
ptr = malloc(sizeof(Post));
strcpy(ptr->author, author->name);
strcpy(ptr->contents, contents);
ptr->date = &date;
ptr->next = NULL;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-15T23:23:42.197Z
|
Question from Code
|
v1
|
how to allocate contents?
|
typedef struct post {
char author[MAX_NAME];
char *contents;
time_t *date;
struct post *next;
} Post;
int main(){
time_t date;
time(&date);
Post *ptr;
ptr = malloc(sizeof(Post));
strcpy(ptr->author, author->name);
strcpy(ptr->contents, contents);
ptr->date = &date;
ptr->next = NULL;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-02-17T13:18:20.868Z
|
General Question
|
v1
|
Does the for-loop counter disappear after the loop stoped
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-02-17T13:20:02.965Z
|
Question from Code
|
v1
|
show the standard outpuy
|
for (int i=0; i < 5; i++){
printf("%d\n", i);
}
printf("%d\n", i+1);
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-10T11:53:08.513Z
|
General Question
|
v2
|
what does dup2 function do
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T10:39:09.789Z
|
General Question
|
v2
|
do you know current CSC209 A3?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T10:41:04.888Z
|
General Question
|
v2
|
How to read lines of a makefile?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T14:04:12.367Z
|
Question from Code
|
v2
|
What does this function return if line is empty?
|
int is_comment_or_empty(const char *line) {
for (int i = 0; i < strlen(line); i++) {
if (line[i] == '#') {
return 1;
}
if (line[i] != '\t' && line[i] != ' ') {
return 0;
}
}
return 1;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T14:05:38.657Z
|
General Question
|
v2
|
How to separate a string by " "?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T15:21:47.712Z
|
General Question
|
v2
|
should we always allocate spaces on the heap for structs if we want to get access to it after function returns?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T15:29:59.077Z
|
Question from Code
|
v2
|
what will this file print?
|
#include <stdio.h>
#include <string.h>
int main() {
char str[80] = "This is - www.tutorialspoint.com - website";
const char s[2] = "-";
char *token;
token = strtok(str, s);
while (token != NULL) {
printf(" %s\n", token);
token = strtok(NULL, s);
}
return (0);
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T17:46:50.070Z
|
General Question
|
v2
|
What will fgets() function get if the line is empty
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T17:49:18.102Z
|
General Question
|
v2
|
How to strip a string after using fgets()?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T18:28:09.774Z
|
Question from Code
|
v2
|
what will it print?
|
#include <stdio.h>
#include <string.h>
int main() {
char str[100] = "Hello, world!\n";
char *token;
token = strtok(str, "\n"); // split the string at "\n"
strcat(token, ""); // concatenate the tokens to get the final string
printf("%s", token); // print the string without "\n"
return 0;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T18:28:51.032Z
|
General Question
|
v2
|
what will it print?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T18:29:21.579Z
|
Question from Code
|
v2
|
what will it print?
|
#include <stdio.h>
#include <string.h>
int main() {
char str[100] = "Hello, world!\n";
char *token;
str = strtok(str, "\n"); // split the string at "\n"
strcat(str, ""); // concatenate the tokens to get the final string
printf("%s", str); // print the string without "\n"
return 0;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T18:30:02.128Z
|
Question from Code
|
v2
|
what will it print?
|
#include <stdio.h>
#include <string.h>
int main() {
char str[100] = "Hello, world!\n";
char *token;
str = strtok(str, "\n"); // split the string at "\n"
// strcat(str, ""); // concatenate the tokens to get the final string
printf("%s", str); // print the string without "\n"
return 0;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T19:55:52.117Z
|
General Question
|
v2
|
If I have a pointer of a struct Rule called rule1, and another pointer pointing to the same thing. Then the first pointer point to another struct Rule called rule2. What will pointer 2 be?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T20:16:53.617Z
|
Question from Code
|
v2
|
is line 7 correct?
|
#include <stdio.h>
#include <string.h>
int main() {
char str[100] = "Hello, world!\n";
str = strtok(str, "\n"); // split the string at "\n"
strcat(str, ""); // concatenate the tokens to get the final string
printf("%s", str); // print the string without "\n"
return 0;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T20:19:09.446Z
|
Question from Code
|
v2
|
is line 7 correct?
|
#include <stdio.h>
#include <string.h>
int main() {
char *str = "Hello, world!\n";
str = strtok(str, "\n"); // split the string at "\n"
strcat(str, ""); // concatenate the tokens to get the final string
printf("%s", str); // print the string without "\n"
return 0;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T20:22:18.349Z
|
Question from Code
|
v2
|
is line 7 correct?
|
#include <stdio.h>
#include <string.h>
int main() {
char str[100] = "Hello, world!\n";
char *token;
token = strtok(str, "\n"); // split the string at "\n"
strcpy(str, token);
printf("%s", str); // print the string without "\n"
return 0;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T20:23:53.994Z
|
Question from Code
|
v2
|
is line 7 correct?
|
#include <stdio.h>
#include <string.h>
int main() {
char str[100] = "Hello, world!\n";
char *token;
token = strtok(str, "\n"); // split the string at "\n"
printf("%s", token); // print the string without "\n"
return 0;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T20:27:30.385Z
|
Question from Code
|
v2
|
what will str be after line 8?
|
#include <stdio.h>
#include <string.h>
int main() {
char str[100] = "Hello, world!\n";
char *token;
token = strtok(str, "\n"); // split the string at "\n"
strcpy(str, token);
printf("%s", token); // print the string without "\n"
return 0;
}
| null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T23:31:50.979Z
|
General Question
|
v2
|
How to read a file again?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T23:33:14.134Z
|
General Question
|
v2
|
how to read a file twice in a function
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-13T23:40:59.960Z
|
General Question
|
v2
|
what does fgets() return?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-14T17:41:53.345Z
|
General Question
|
v2
|
how to report error if error occurred during malloc?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-14T20:25:28.265Z
|
General Question
|
v2
|
if I split a string "\t hello world" by strtok, what will the result be?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-14T20:28:53.200Z
|
General Question
|
v2
|
If I use strtok() to a string contains '\t' by delimiter " ", and then I keep printing strtok(NULL, space), will '\t' be printed out?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-14T21:17:13.541Z
|
General Question
|
v2
|
How to debug using terminal
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-14T21:53:41.562Z
|
General Question
|
v2
|
how to copy a string?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-14T22:04:35.138Z
|
General Question
|
v2
|
what does \r mean?
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-14T22:14:08.467Z
|
General Question
|
v2
|
how to use strtok to strip \n and \r
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-14T22:17:44.428Z
|
General Question
|
v2
|
explain strncpy()
| null | null | null |
63c647f55f004bf4898cf82e
|
2023-03-14T22:30:37.678Z
|
General Question
|
v2
|
how to strip '\n' of a string by using strtok
| null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.