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
⌀ |
---|---|---|---|---|---|---|---|
63c6477f5f004bf4898cf441 | 2023-01-21T07:02:47.356Z | Explain Code | v1 | null | scanf("%c%s %*s %*s %*s %s", &type, perms, file_mem) | null | null |
63c6477f5f004bf4898cf441 | 2023-01-21T07:11:13.887Z | General Question | v1 | generate a detailed documentation of `%*[^\n]` with usage examples and explanations | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-21T07:19:33.836Z | General Question | v1 | what is the format specifier for a char
| null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-21T07:21:37.645Z | General Question | v1 | first character is empty when using the format specifier %*[^\n] | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-21T07:22:56.178Z | General Question | v1 | discard newline in scanf | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-21T08:12:24.774Z | General Question | v1 | how to call a function located in file A from file B in the C programming language | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-21T22:03:07.292Z | Question from Code | v1 | will this code return 1? | if (-1) {
return 1;
}
return 0; | null | null |
63c6477f5f004bf4898cf441 | 2023-01-21T22:12:19.966Z | General Question | v1 | %3s in scanf will only check for 3 characters? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-23T05:34:12.373Z | General Question | v1 | expected ‘char **’ but argument is of type ‘char (*)[50]’
how would i fix this issue? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-23T05:35:40.927Z | Question from Code | v1 | why would this code have issues? | void ask(char *arg[20]);
int main() {
char potato[20];
ask(&potato);
return 0;
} | null | null |
63c6477f5f004bf4898cf441 | 2023-01-23T05:43:27.836Z | General Question | v1 | is the null pointer always added to a string? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-23T05:53:01.631Z | General Question | v1 | what would tar -czvf do? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-24T04:59:58.297Z | General Question | v1 | what is $@ and $^ in bash scripting? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-24T05:18:49.519Z | General Question | v1 | what is $@, $^, and $< in bash scripting? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-24T05:20:55.883Z | General Question | v1 | what is % in bash scripting? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-24T05:21:26.008Z | General Question | v1 | what is % in bash scripting for a makefile? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-24T06:09:13.800Z | General Question | v1 | pointer arithmetic with an array looks like? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-24T06:10:25.052Z | General Question | v1 | does sizeof function of an array return the length? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-24T06:33:10.433Z | General Question | v1 | let there be char **argv. when we do argv + 1, we are starting from the second element in the argv array of char pointers? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-24T06:36:25.124Z | Question from Code | v1 | does line 2 give the number of elements in argv? | char **argv;
sizeof(argv) / sizeof(char**) | null | null |
63c6477f5f004bf4898cf441 | 2023-01-27T22:46:03.530Z | General Question | v1 | Explain the strtok function in C. What is a token and a delimiter? How are they used? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-01-27T22:50:01.680Z | General Question | v1 | In C, if i call the error function with a string, it would print an error with that string? For example, if I had error("too many characters"); then the error would be "too many characters"? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-02-01T07:28:11.617Z | Question from Code | v1 | On line 2, why does this not work? Why do we need to use strcpy? | char s[] = "Hello";
s = "Bye"; | null | null |
63c6477f5f004bf4898cf441 | 2023-02-01T07:31:18.955Z | Question from Code | v1 | Does variable p get assigned to Smith after the program ends? | char s[] = "Hello";
s = "Bye";
char *p = "Joe";
p = "Smith"; | null | null |
63c6477f5f004bf4898cf441 | 2023-02-01T07:32:08.620Z | Question from Code | v1 | Why does p get assigned to "Smith" but s does not get assigned to "Bye"? | char s[] = "Hello";
s = "Bye";
char *p = "Joe";
p = "Smith"; | null | null |
63c6477f5f004bf4898cf441 | 2023-02-01T07:34:09.466Z | General Question | v1 | Why can you not reassign arrays in C? Is there a historical explanation for this? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-02-01T07:34:46.347Z | General Question | v1 | Why can you not re-assign arrays? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-02-01T07:36:22.135Z | Question from Code | v1 | Will this work properly in C? | char s[] = "Hello";
char s[] = "Goodbye"; | null | null |
63c6477f5f004bf4898cf441 | 2023-02-07T20:50:27.481Z | General Question | v1 | what is memcpy? how does it work? why? | null | null | null |
63c6477f5f004bf4898cf441 | 2023-02-14T03:00:31.934Z | Question from Code | v1 | What will be the behaviour of this program? Will the strncpy keep on copying all 10 bytes or will it know that s contains space for only 5 bytes and stop? | char s[5];
strncpy(s, "hello world!!!!!!", 10); | null | null |
63c647805f004bf4898cf446 | 2023-01-17T22:07:28.482Z | General Question | v1 | how to code in C | null | null | null |
63c647805f004bf4898cf446 | 2023-01-18T21:14:14.771Z | General Question | v1 | how to input a string
| null | null | null |
63c647805f004bf4898cf446 | 2023-01-18T21:17:38.341Z | Explain Code | v1 | null | char phone[11];
int keypad;
scanf("%s %d", &phone, &keypad); | null | null |
63c647805f004bf4898cf44b | 2023-02-02T01:38:59.247Z | General Question | v1 | How to compare two strings
| null | null | null |
63c647805f004bf4898cf44b | 2023-02-02T02:06:03.311Z | Help Fix Code | v1 | null | int **result = malloc(sizeof(int*) * 2);
result[0] = malloc(sizeof(int) * ((length + 1)/ 2));
result[1] = malloc(sizeof(int) * length / 2); | what malloc is incorrectly allocated
| null |
63c647805f004bf4898cf44b | 2023-02-02T02:12:25.517Z | General Question | v1 | how to change a string array | null | null | null |
63c647805f004bf4898cf44b | 2023-02-02T02:13:06.232Z | General Question | v1 | how to mutate a char array. | null | null | null |
63c647805f004bf4898cf44b | 2023-02-02T02:22:29.265Z | Help Fix Code | v1 | null | char tempString[strlen(s)] = s;
strncpy(s, tempString, n);
strlen(tempString); | creating a copy of s char
| null |
63c647805f004bf4898cf44b | 2023-02-12T18:57:05.809Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *newUser = malloc(sizeof(User));
strcpy(newUser->name, name);
User *curr = user_ptr_add;
while (curr != NULL)
{
curr = curr->next;
}
curr = newUser;
} | is assignment and traversal correct | null |
63c647805f004bf4898cf44b | 2023-02-12T18:58:43.637Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *newUser = malloc(sizeof(User));
strcpy(newUser->name, name);
User *curr = *user_ptr_add;
while (curr != NULL)
{
curr = curr->next;
}
curr = newUser;
} | is traversal of linked list correct | null |
63c647805f004bf4898cf44b | 2023-02-12T19:01:43.401Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *newUser = malloc(sizeof(User));
strcpy(newUser->name, name);
User *curr = *user_ptr_add;
while (curr != NULL)
{
curr = curr->next;
}
curr = newUser;
} | add user at the end of the list | null |
63c647805f004bf4898cf44b | 2023-02-12T19:02:57.581Z | General Question | v1 | how to add a item at the end of linked list | null | null | null |
63c647805f004bf4898cf44b | 2023-02-12T19:06:50.007Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *newUser = malloc(sizeof(User));
strcpy(newUser->name, name);
User *curr = *user_ptr_add;
while (curr != NULL)
{
curr = curr->next;
}
curr = newUser;
newUser-> = NULL;
} | newUser should be at the end of the linked list | null |
63c647805f004bf4898cf44b | 2023-02-12T19:07:45.488Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *newUser = malloc(sizeof(User));
strcpy(newUser->name, name);
User *curr = *user_ptr_add;
while (curr != NULL)
{
curr = curr->next;
}
curr->next = newUser;
newUser-> = NULL;
} | adding user at the end of the linked list | null |
63c647805f004bf4898cf44b | 2023-02-12T19:08:43.422Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *newUser = malloc(sizeof(User));
strcpy(newUser->name, name);
User *curr = *user_ptr_add;
while (curr != NULL)
{
curr = curr->next;
}
curr = newUser;
newUser->next = NULL;
} | how do you add new user to the end of linked list | null |
63c647805f004bf4898cf44b | 2023-02-12T19:14:41.645Z | Help Fix Code | v1 | null | int create_user(const char *name, User **user_ptr_add) {
User *newUser = malloc(sizeof(User));
strcpy(newUser->name, name);
User *curr = *user_ptr_add;
if (curr == NULL) {
curr = newUser;
curr->next = NULL;
return 0;
}
} | w | null |
63c647805f004bf4898cf44b | 2023-02-12T20:18:38.249Z | Help Fix Code | v1 | null | int update_pic(User *user, const char *filename) {
if (sizeof(filename) > 31) {
return 2;
} else if (fopen(filename, "r") == NULL)
{
return 1;
} else {
strncpy(user->profile_pic, filename, 32);
} | open the file and assign it to user profile pic | null |
63c647805f004bf4898cf44b | 2023-02-12T20:47:10.873Z | Help Fix Code | v1 | null | User *find_user(const char *name, const User *head) {
User *curr = (User *) head;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
return curr;
}
head = head->next;
return 0;
}
return NULL;
} | return pointer to the user | null |
63c647805f004bf4898cf44b | 2023-02-12T21:02:58.711Z | General Question | v1 | how to compare two strings | null | null | null |
63c647805f004bf4898cf44b | 2023-02-12T23:07:33.997Z | General Question | v1 | check if string array is empty | null | null | null |
63c647805f004bf4898cf44b | 2023-02-13T00:53:30.863Z | Help Fix Code | v1 | null | (User *)author->first_post = &newPost; | author a struct should point to new post which is another struct | null |
63c647805f004bf4898cf44b | 2023-02-13T00:54:18.376Z | Help Fix Code | v1 | null | author->first_post = &newPost; | author struct should point to newpost which is another struct | null |
63c647805f004bf4898cf44b | 2023-02-13T00:55:12.736Z | Help Fix Code | v1 | null | author->first_post = newPost; | author struct with property first_post should point to another struct newpost | null |
63c647805f004bf4898cf44b | 2023-02-14T03:39:10.894Z | Help Fix Code | v1 | null | Post *newPost = malloc(sizeof(Post));
author->first_post = newPost; | author first post should point to new post | null |
63c647805f004bf4898cf44b | 2023-02-14T03:40:18.878Z | Help Fix Code | v1 | null | Post *newPost = malloc(sizeof(Post));
author->first_post = newPost;
strncpy(newPost->author, author->name, MAX_NAME);
newPost->author[MAX_NAME-1] ='\0';
newPost->contents = contents;
newPost->next = NULL; | author first post should newPost | null |
63c647805f004bf4898cf44b | 2023-02-14T05:46:03.550Z | Help Fix Code | v1 | null | Post *prevPost = target->first_post;
newPost->next = prevPost;
target->first_post = newPost; | insert before the first_post | null |
63c647805f004bf4898cf44b | 2023-02-14T05:56:33.297Z | Help Fix Code | v1 | null | Post *newPost = malloc(sizeof(Post));
strncpy(newPost->author, author->name, MAX_NAME);
newPost->author[MAX_NAME-1] ='\0';
newPost->contents = contents;
time_t current_time = time(NULL);
newPost->date = ¤t_time;
if (target->first_post == NULL) {
newPost->next = NULL;
target->first_post = newPost;
} else {
newPost->next = target->first_post;
target->first_post = newPost;
}
} | new post should be inserted in front of the linked list | null |
63c647805f004bf4898cf44b | 2023-02-14T05:57:22.859Z | Help Fix Code | v1 | null | Post *newPost = malloc(sizeof(Post));
strncpy(newPost->author, author->name, MAX_NAME);
newPost->author[MAX_NAME-1] ='\0';
newPost->contents = contents;
if (target->first_post == NULL) {
newPost->next = NULL;
target->first_post = newPost;
} else {
newPost->next = target->first_post;
target->first_post = newPost;
}
} | new post should be inserted infront of the list | null |
63c647805f004bf4898cf44b | 2023-02-15T01:27:49.237Z | Help Fix Code | v1 | null | time_t current_time = time(NULL);
newPost->date = ¤t_time; | storing current time as a date in newPost | null |
63c647805f004bf4898cf44b | 2023-02-15T02:58:54.971Z | Help Fix Code | v1 | null | for (int i = 0; i < MAX_FRIENDS; i++) {
User *userFriend = find_user(curr->friends[i]->name, *user_ptr_del);
if (userFriend != NULL) {
for (int j = 0; j < MAX_FRIENDS; j++) {
if (userFriend->friends[j] != NULL && strcmp(userFriend->friends[j]->name, curr->name) == 0) {
userFriend->friends[j] = NULL;
break;
}
}
}
} | remove curr from curr friend's list. | null |
63c647805f004bf4898cf44b | 2023-02-16T02:22:47.497Z | Help Fix Code | v1 | null | char *copy(char *dest, const char *src, int capacity) {
//dest = destination string
// copy from source and dest
int counter = 0;
while (src[counter] != '\0' || counter < capacity) {
dest[counter] = src[counter];
}
dest[counter - 1] = '\0';
return dest;
} | copy char from src to dest | null |
63c647805f004bf4898cf44b | 2023-03-09T03:53:45.740Z | Help Fix Code | v1 | null | if (strcmp(token, ":") == 0) {
bool = 1;
} | checking if current token is a colon | null |
63c647815f004bf4898cf450 | 2023-02-08T05:29:13.121Z | General Question | v1 | I am getting a segmentation fault when I run this on a bitmap display | null | null | null |
63c647815f004bf4898cf450 | 2023-02-08T05:30:06.212Z | General Question | v1 | I am getting a segmentation fault on this code | null | null | null |
63c647815f004bf4898cf450 | 2023-02-08T05:30:39.505Z | Question from Code | v1 | I am getting a seg fault | struct pixel **read_pixel_array(FILE *image, int pixel_array_offset, int width, int height) {
struct pixel** pixel_data_start = malloc(sizeof(struct pixel*)*height);
fseek(image, pixel_array_offset, SEEK_SET);
for (int i = 0; i < height; i++){
pixel_data_start[i] = malloc(sizeof(struct pixel)*width);
for (int j = 0; j < width; j++){
unsigned char blue;
fread(&blue, sizeof(unsigned char), 1, image);
unsigned char green;
fread(&green, sizeof(unsigned char), 1, image);
unsigned char red;
fread(&red, sizeof(unsigned char), 1, image);
struct pixel pix = {blue, green, red};
pixel_data_start[i][j] = pix;
}
}
return pixel_data_start;
} | null | null |
63c647835f004bf4898cf45f | 2023-03-18T00:58:48.841Z | General Question | v2 | what does the mask do for sigaction?
| null | null | null |
63c647835f004bf4898cf45f | 2023-03-18T01:00:56.472Z | General Question | v2 | what types of signals cannot be blocked? | null | null | null |
63c647835f004bf4898cf45f | 2023-03-18T01:02:51.379Z | Explain Code | v2 | null | struct itimerval timer_info;
// Makes alarm happen only once
timer_info.it_interval.tv_sec = 0;
timer_info.it_interval.tv_usec = 0;
// Sent it after s seconds
timer_info.it_value.tv_sec = 1;
timer_info.it_value.tv_usec = 0;
if (setitimer(ITIMER_PROF, &timer_info, NULL) == -1) {
perror("setitimer");
exit(1);
} | null | null |
63c647845f004bf4898cf46e | 2023-02-11T21:00:09.195Z | Help Fix Code | v1 | null |
int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = NULL;
User *user2 = NULL;
int friend_count1 = 0;
int friend_count2 = 0;
// Find the two users with the given names
User *current = head;
while (current != NULL) {
if (strcmp(current->name, name1) == 0) {
user1 = current;
} if (strcmp(current->name, name2) == 0) {
user2 = current;
}
if (user1 != NULL && user2 != NULL) {
break;
}
}
// Check if at least one user does not exist and return 4 if so is true
if (user1 == NULL || user2 == NULL) {
return 4;
}
// Check if the same user is passed in twice and return 3 if so is true
if (user1 == user2) {
return 3;
}
// Create marker to be used to check if already friends
int marker = 0;
// Check if the two users are already friends and return 1 if so is true
for (int i = 0; i < MAX_FRIENDS; i++) {
if (user1->friends[i] == user2) {
marker = 1;
}
if (user2->friends[i] == user1) {
marker = 1;
}
if (user1->friends[i] == NULL) {
friend_count1++;
}
if (user2->friends[i] == NULL) {
friend_count2++;
}
}
// Check if at least one user has MAX_FRIENDS friends
if (friend_count1 == 0 || friend_count2 == 0) {
return 2;
}
// Return 1 if users are already friends and none of the other error return statements apply
if (marker == 1) return 1;
// Make the two users friends with each other
user1->friends[MAX_FRIENDS - friend_count1] = user2;
user2->friends[MAX_FRIENDS - friend_count2] = user1;
return 0;
} | /*
* 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.
*/ | null |
63c647845f004bf4898cf46e | 2023-02-11T21:03:37.846Z | Help Fix Code | v1 | null | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
bool is_friends = false;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (target->friends[i] == author) {
is_friends = true;
break;
}
}
if (!is_friends) {
return 1;
}
Post *new_post = (Post *)malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
new_post->date = (time_t *)ctime(NULL);
new_post->next = target->first_post;
target->first_post = new_post;
return 0;
}
| /*
* 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
*/ | null |
63c647845f004bf4898cf46e | 2023-02-11T21:11:02.531Z | Help Fix Code | v1 | null | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
bool is_friends = false;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (target->friends[i] == author) {
is_friends = true;
break;
}
}
if (!is_friends) {
return 1;
}
Post *new_post = (Post *)malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
new_post->date = (time_t *)ctime(NULL);
new_post->next = target->first_post;
target->first_post = new_post;
return 0;
}
| /*
* 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
*/
How would you go about inserting the new post at the front of the list? | null |
63c647845f004bf4898cf46e | 2023-02-11T21:11:34.688Z | Help Fix Code | v1 | null | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
bool is_friends = false;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (target->friends[i] == author) {
is_friends = true;
break;
}
}
if (!is_friends) {
return 1;
}
Post *new_post = (Post *)malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
new_post->date = (time_t *)ctime(NULL);
new_post->next = target->first_post;
target->first_post = new_post;
return 0;
}
| /*
* 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
*/ | null |
63c647845f004bf4898cf46e | 2023-02-12T00:18:14.686Z | Help Fix Code | v1 | null | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
bool is_friends = false;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (target->friends[i] == author) {
is_friends = true;
break;
}
}
if (!is_friends) {
return 1;
}
Post *new_post = (Post *)malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
new_post->date = (time_t *)malloc(sizeof(time_t));
time(new_post->date);
new_post->next = target->first_post;
target->first_post = new_post;
return 0;
} |
/*
* 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
*/ | null |
63c647845f004bf4898cf46e | 2023-02-12T00:45:41.726Z | Help Fix Code | v1 | null | int make_friends(const char *name1, const char *name2, User *head) {
User *user1 = NULL;
User *user2 = NULL;
int friend_count1 = 0;
int friend_count2 = 0;
// Find the two users with the given names
User *current = head;
while (current != NULL) {
if (strcmp(current->name, name1) == 0) {
user1 = current;
} if (strcmp(current->name, name2) == 0) {
user2 = current;
}
if (user1 != NULL && user2 != NULL) {
break;
}
current = current->next;
}
// Check if at least one user does not exist and return 4 if so is true
if (user1 == NULL || user2 == NULL) {
return 4;
}
// Check if the same user is passed in twice and return 3 if so is true
if (user1 == user2) {
return 3;
}
// Create marker to be used to check if already friends
int marker = 0;
// Check if the two users are already friends and return 1 if so is true
for (int i = 0; i < MAX_FRIENDS; i++) {
if (user1->friends[i] == user2) {
marker = 1;
}
if (user2->friends[i] == user1) {
marker = 1;
}
if (user1->friends[i] == NULL) {
friend_count1++;
}
if (user2->friends[i] == NULL) {
friend_count2++;
}
}
// Check if at least one user has MAX_FRIENDS friends
if (friend_count1 == 0 || friend_count2 == 0) {
return 2;
}
// Return 1 if users are already friends and none of the other error return statements apply
if (marker == 1) return 1;
// Make the two users friends with each other
user1->friends[MAX_FRIENDS - friend_count1] = user2;
user2->friends[MAX_FRIENDS - friend_count2] = user1;
return 0;
} | *
* 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.
*/ | null |
63c647845f004bf4898cf46e | 2023-02-12T01:20:32.849Z | Help Fix Code | v1 | null |
int delete_user(const char *name, User **user_ptr_del) {
User *prev = NULL;
User *curr = *user_ptr_del;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
// remove user from friends lists
int i, j;
for (i = 0; i < MAX_FRIENDS; i++) {
User *friend = curr->friends[i];
if (!friend) continue;
for (j = 0; j < MAX_FRIENDS; j++) {
if (friend->friends[j] == curr) {
friend->friends[j] = NULL;
break;
}
}
}
// remove user from linked list
if (prev == NULL) {
*user_ptr_del = curr->next;
} else {
prev->next = curr->next;
}
// free memory
Post *post = curr->first_post;
while (post != NULL) {
Post *temp = post->next;
free(post->contents);
free(post);
post = temp;
}
free(curr);
return 0;
}
prev = curr;
curr = curr->next;
}
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.
*/ | null |
63c647845f004bf4898cf46e | 2023-02-12T02:03:35.602Z | Help Fix Code | v1 | null | int delete_user(const char *name, User **user_ptr_del) {
User *prev = NULL;
User *curr = *user_ptr_del;
while (curr != NULL) {
// remove user from friend's list
if (strcmp(curr->name, name) == 0) {
// remove current user from all friends
int i, j;
for (i = 0; i < MAX_FRIENDS; i++) {
User *friend = curr->friends[i];
if (!friend) continue;
for (j = 0; j < MAX_FRIENDS; j++) {
if (friend->friends[j] == curr) {
// move all friends after current to the left
int k;
for (k = j; k < MAX_FRIENDS - 1; k++) {
friend->friends[k] = friend->friends[k + 1];
}
// clear the last friend
friend->friends[MAX_FRIENDS - 1] = NULL;
break;
}
}
}
// remove current user from linked list
if (prev == NULL) {
*user_ptr_del = curr->next;
} else {
prev->next = curr->next;
}
// free memory of post
Post *post = curr->first_post;
while (post != NULL) {
Post *temp = post->next;
free(post->contents);
free(post);
post = temp;
}
free(curr);
return 0;
}
prev = curr;
curr = curr->next;
}
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.
*/ | null |
63c647845f004bf4898cf46e | 2023-02-12T02:05:05.398Z | Help Fix Code | v1 | null | int delete_user(const char *name, User **user_ptr_del) {
User *prev = NULL;
User *curr = *user_ptr_del;
while (curr != NULL) {
// remove user from friend's list
if (strcmp(curr->name, name) == 0) {
// remove current user from all friends
int i, j;
for (i = 0; i < MAX_FRIENDS; i++) {
User *friend = curr->friends[i];
if (!friend) continue;
for (j = 0; j < MAX_FRIENDS; j++) {
if (friend->friends[j] == curr) {
// move all friends after current to the left
int k;
for (k = j; k < MAX_FRIENDS - 1; k++) {
friend->friends[k] = friend->friends[k + 1];
}
// clear the last friend
friend->friends[MAX_FRIENDS - 1] = NULL;
break;
}
}
}
// remove current user from linked list
if (prev == NULL) {
*user_ptr_del = curr->next;
} else {
prev->next = curr->next;
}
// free memory of post
Post *post = curr->first_post;
while (post != NULL) {
Post *temp = post->next;
free(post->contents);
free(post);
post = temp;
}
free(curr);
return 0;
}
prev = curr;
curr = curr->next;
}
return 1;
} | It must remove the user from the list of users
It must remove the user from all user's friends lists.
It must remove the user's posts from all user's posts lists. | null |
63c647845f004bf4898cf46e | 2023-02-12T02:05:57.533Z | Explain Code | v1 | null | int delete_user(const char *name, User **user_ptr_del) {
User *prev = NULL;
User *curr = *user_ptr_del;
while (curr != NULL) {
// remove user from friend's list
if (strcmp(curr->name, name) == 0) {
// remove current user from all friends
int i, j;
for (i = 0; i < MAX_FRIENDS; i++) {
User *friend = curr->friends[i];
if (!friend) continue;
for (j = 0; j < MAX_FRIENDS; j++) {
if (friend->friends[j] == curr) {
// move all friends after current to the left
int k;
for (k = j; k < MAX_FRIENDS - 1; k++) {
friend->friends[k] = friend->friends[k + 1];
}
// clear the last friend
friend->friends[MAX_FRIENDS - 1] = NULL;
break;
}
}
}
// remove current user from linked list
if (prev == NULL) {
*user_ptr_del = curr->next;
} else {
prev->next = curr->next;
}
// free memory of post
Post *post = curr->first_post;
while (post != NULL) {
Post *temp = post->next;
free(post->contents);
free(post);
post = temp;
}
free(curr);
return 0;
}
prev = curr;
curr = curr->next;
}
return 1;
} | null | null |
63c647845f004bf4898cf46e | 2023-02-12T02:34:32.075Z | Help Fix Code | v1 | null | #include "friends.h"
#include <string.h>
#include <stdbool.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) {
User *current = *user_ptr_add;
while (current != NULL) {
if (strcmp(current->name, name) == 0) {
return 1;
}
current = current->next;
}
if (strlen(name) >= MAX_NAME) {
return 2;
}
// must cast to be of type User*
User *new_user = (User*) malloc(sizeof(User));
strcpy(new_user->name, name);
new_user->next = NULL;
if (*user_ptr_add == NULL) {
*user_ptr_add = new_user;
} else {
current = *user_ptr_add;
while (current->next != NULL) {
current = current->next;
}
current->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) {
User *current = (User *) head;
// Iterate through the list of users starting at head until username is name
while (current != NULL){
if (strcmp(current->name, name)== 0){
return (User *) current;
}
current = current -> 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 != NULL){
printf("\t%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");
if (file == NULL) {
return 1;
}
if (strlen(filename) >= MAX_NAME) {
return 2;
}
strcpy(user->profile_pic, filename);
fclose(file);
return 0;
}
/*
* 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) {
User *user1 = NULL;
User *user2 = NULL;
// Find the two users with the given names
User *current = head;
while (current != NULL) {
if (strcmp(current->name, name1) == 0) {
user1 = current;
} if (strcmp(current->name, name2) == 0) {
user2 = current;
}
if (user1 != NULL && user2 != NULL) {
break;
}
current = current->next;
}
// Check if at least one user does not exist and return 4 if so is true
if (user1 == NULL || user2 == NULL) {
return 4;
}
// Check if the same user is passed in twice and return 3 if so is true
if (user1 == user2) {
return 3;
}
// Create marker to be used to check if already friends
int marker = 0;
int friend_count1 = MAX_FRIENDS;
int friend_count2 = MAX_FRIENDS;
// Check if the two users are already friends and return 1 if so is true
for (int i = 0; i < MAX_FRIENDS; i++) {
if (user1->friends[i] == user2) {
marker = 1;
}
if (user2->friends[i] == user1) {
marker = 1;
}
if (user1->friends[i] != NULL) {
friend_count1--;
}
if (user2->friends[i] != NULL) {
friend_count2--;
}
}
// Check if at least one user has MAX_FRIENDS friends
if (friend_count1 == 0 || friend_count2 == 0) {
return 2;
}
// Return 1 if users are already friends and none of the other error return statements apply
if (marker == 1) return 1;
// Make the two users friends with each other
user1->friends[MAX_FRIENDS - friend_count1] = user2;
user2->friends[MAX_FRIENDS - friend_count2] = user1;
return 0;
}
/*
* 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;
}
if (user->profile_pic != NULL){
FILE *fp;
char line[100000];
fp = fopen(user->profile_pic, "r");
if (fp == NULL) {
printf("Error opening file\n");
return 1;
}
while (fgets(line, 10000, fp) != NULL) {
printf("%s", line);
}
fclose(fp);
}
printf("\nName: %s\n", user->name);
printf("------------------------------------------\n");
printf("Friends:\n");
for (int i = 0; i < MAX_FRIENDS; i++) {
if (user->friends[i] == NULL) {
break;
}
printf("%s\n", user->friends[i]->name);
}
printf("------------------------------------------\n");
printf("Posts:\n");
Post *curr = user->first_post;
int counter = 1;
while (curr != NULL){
if (counter > 1){
printf("\n\n===\n\n");
}
printf("From: %s\nDate: %s\n%s\n", curr->author, ctime(curr->date), curr->contents);
curr = curr -> next;
counter++;
}
printf("------------------------------------------\n");
return 0;
}
/*
* 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;
}
bool is_friends = false;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (target->friends[i] == author) {
is_friends = true;
break;
}
}
if (!is_friends) {
return 1;
}
Post *new_post = (Post *)malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
new_post->date = (time_t *)malloc(sizeof(time_t));
time(new_post->date);
new_post->next = target->first_post;
target->first_post = new_post;
return 0;
}
| When creating a user profile the profile should be printed correctly after a user was added | null |
63c647845f004bf4898cf46e | 2023-02-12T02:56:31.325Z | Help Fix Code | v1 | null | int print_user(const User *user) {
if (user == NULL) {
return 1;
}
if (user->profile_pic[0] == '\0'){
FILE *fp;
char line[100000];
fp = fopen(user->profile_pic, "r");
if (fp == NULL) {
printf("Error opening file\n");
return 1;
}
while (fgets(line, 10000, fp) != NULL) {
printf("%s", line);
}
fclose(fp);
}
printf("\nName: %s\n", user->name);
printf("------------------------------------------\n");
printf("Friends:\n");
for (int i = 0; i < MAX_FRIENDS; i++) {
if (user->friends[i] == NULL) {
break;
}
printf("%s\n", user->friends[i]->name);
}
printf("------------------------------------------\n");
printf("Posts:\n");
Post *curr = user->first_post;
int counter = 1;
while (curr != NULL){
if (counter > 1){
printf("\n\n===\n\n");
}
printf("From: %s\nDate: %s\n%s\n", curr->author, ctime(curr->date), curr->contents);
curr = curr -> next;
counter++;
}
printf("------------------------------------------\n");
return 0;
} | To print out the profile of the user | null |
63c647845f004bf4898cf46e | 2023-02-12T18:13:42.671Z | Help Fix Code | v1 | null | int make_post(const User *author, User *target, char *contents) {
if (author == NULL || target == NULL) {
return 2;
}
bool is_friends = false;
for (int i = 0; i < MAX_FRIENDS; i++) {
if (target->friends[i] == author) {
is_friends = true;
break;
}
}
if (!is_friends) {
return 1;
}
Post *new_post = (Post *)malloc(sizeof(Post));
strncpy(new_post->author, author->name, MAX_NAME - 1);
new_post->author[MAX_NAME - 1] = '\0';
new_post->contents = contents;
new_post->date = (time_t *)malloc(sizeof(time_t));
time(new_post->date);
new_post->next = target->first_post;
target->first_post = new_post;
free(new_post->date);
free(new_post);
return 0;
} | Free the memory correctly | null |
63c647845f004bf4898cf46e | 2023-03-11T02:08:32.491Z | Help Fix Code | v2 | Part of a function called run_make which should check if the target in the make file exists nd is up to date. | // check if the target exists and is up to date
struct stat target_stat;
struct stat dep_stat;
if (stat(rule->target, &target_stat) == 0) {
// target file exists
int up_to_date = 1;
for (Dependency *dep = rule->dependencies; dep != NULL; dep = dep->next_dep) {
if (stat(dep->rule->target, &dep_stat) != 0) {
// dependency file doesn't exist, so target is not up to date
up_to_date = 0;
break;
}
if (dep_stat.st_mtim.tv_sec > target_stat.st_mtim.tv_sec ||
(dep_stat.st_mtim.tv_sec == target_stat.st_mtim.tv_sec &&
dep_stat.st_mtim.tv_nsec > target_stat.st_mtim.tv_nsec)) {
// dependency file is more recent than target file
up_to_date = 0;
break;
}
}
if (up_to_date) {
// target is up to date, so no need to run actions
return;
}
} | null | null |
63c647845f004bf4898cf46e | 2023-03-11T02:11:20.225Z | Help Write Code | v2 | null | null | null | /* Evaluate the rule in rules corresponding to the given target.
If target is NULL, evaluate the first rule instead.
If pflag is 0, evaluate each dependency in sequence.
If pflag is 1, then evaluate each dependency in parallel (by creating one
new process per dependency). In this case, the parent process will wait until
all child processes have terminated before checking dependency modified times
to decide whether to execute the actions.
*/ |
63c647845f004bf4898cf46e | 2023-03-11T02:47:48.372Z | 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 ");
struct sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act, NULL);
x += 2;
fprintf(stderr, "outside %d", x);
return 0;
}
| null | null |
63c647845f004bf4898cf46e | 2023-03-11T02:49:22.917Z | 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 C? | int x = 5;
void handler(int sig) {
x += 3;
fprintf(stderr, "inside %d ", x);
}
int main() {
fprintf(stderr, "start ");
struct sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act, NULL);
x += 2;
fprintf(stderr, "outside %d", x);
return 0;
}
| null | null |
63c647845f004bf4898cf46e | 2023-03-11T02:55:06.354Z | Explain Code | v2 | null | int x = 5;
void handler(int sig) {
x += 3;
fprintf(stderr, "inside %d ", x);
}
int main() {
fprintf(stderr, "start ");
struct sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act, NULL);
x += 2;
fprintf(stderr, "outside %d", x);
return 0;
}
| null | null |
63c647845f004bf4898cf46e | 2023-03-11T02:58:57.194Z | Question from Code | v2 | If you type Ctl+C while this function is running then what happens? | int x = 5;
void handler(int sig) {
x += 3;
fprintf(stderr, "inside %d ", x);
}
int main() {
fprintf(stderr, "start ");
struct sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act, NULL);
x += 2;
fprintf(stderr, "outside %d", x);
return 0;
}
| null | null |
63c647845f004bf4898cf46e | 2023-03-11T20:12:33.279Z | Help Fix Code | v2 | /* 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.
Rule *rules = NULL;
Rule *cur_rule = NULL;
char line[MAXLINE];
while(fgets(line, MAXLINE, fp) != NULL) {
// Skip comments and empty lines
if(is_comment_or_empty(line)) {
continue;
}
// Target line
if(line[0] != '\t') {
// Create a new rule
Rule *rule = malloc(sizeof(Rule));
rule->target = malloc(strlen(strtok(line, ": ")) + 1);
strcpy(rule->target, strtok(line, ": "));
rule->dependencies = NULL;
rule->actions = NULL;
rule->next_rule = NULL;
// Add the new rule to the list of rules
if(rules == NULL) {
rules = rule;
} else {
cur_rule->next_rule = rule;
}
cur_rule = rule;
// Action line
} else {
// Create a new action
Action *act = malloc(sizeof(Action));
act->args = NULL;
act->next_act = NULL;
// Add arguments
int arg_count = 0;
char *arg_str = strtok(line, " \t\n");
while(arg_str != NULL) {
act->args = realloc(act->args, (arg_count + 2) * sizeof(char *));
act->args[arg_count] = malloc(strlen(arg_str) + 1); // Allocate memory
strcpy(act->args[arg_count], arg_str); // Copy string
arg_count++;
arg_str = strtok(NULL, " \t\n");
}
act->args[arg_count] = NULL;
// Add the new action to the current rule
if(cur_rule->actions == NULL) {
cur_rule->actions = act;
} else {
Action *cur_act = cur_rule->actions;
while(cur_act->next_act != NULL) {
cur_act = cur_act->next_act;
}
cur_act->next_act = act;
}
}
}
return rules;
} | null | null |
63c647845f004bf4898cf46e | 2023-03-22T18:35:58.556Z | Help Fix Code | v2 | /*
* Print the usernames of all users in the list starting at curr.
* Names should be printed to standard output, one per line.
* Return a dynamically allocated string containing the list of user names.
*/ | char* list_users(const User *curr) {
char* result = NULL;
int len = 0;
while (curr != NULL) {
len += strlen(curr->name) + 1; // Add 1 for newline character
curr = curr->next;
}
result = (char*) malloc(len + 1); // Add 1 for null terminator
if (result == NULL) {
perror("malloc");
exit(1);
}
char* ptr = result;
curr = curr->next;
while (curr != NULL) {
int n = snprintf(ptr, len, "%s\n", curr->name);
if (n < 0) {
perror("snprintf");
free(result);
exit(1);
}
ptr += n;
len -= n;
curr = curr->next;
}
return result;
} | null | null |
63c647845f004bf4898cf46e | 2023-03-22T18:36:56.986Z | Help Fix Code | v2 | /*
* Print the usernames of all users in the list starting at curr.
* Names should be printed to standard output, one per line.
* Return a dynamically allocated string containing the list of user names.
*/ | char* list_users(const User *curr) {
char* result = NULL;
int len = 0;
while (curr != NULL) {
len += strlen(curr->name) + 1; // Add 1 for newline character
curr = curr->next;
}
result = (char*) malloc(len + 1); // Add 1 for null terminator
if (result == NULL) {
perror("malloc");
exit(1);
}
char* ptr = result;
curr = curr->next;
while (curr != NULL) {
int n = snprintf(ptr, len, "%s\n", curr->name);
if (n < 0) {
perror("snprintf");
free(result);
exit(1);
}
ptr += n;
len -= n;
curr = curr->next;
}
return result;
}
| null | null |
63c647845f004bf4898cf46e | 2023-03-22T18:37:35.954Z | General Question | v2 | Will this give a segmentation fault? | null | null | null |
63c647845f004bf4898cf46e | 2023-03-22T19:44:09.174Z | Explain Code | v2 | null | char* print_user(const User* user) {
if (user == NULL) {
return NULL;
}
int length = 0;
length += snprintf(NULL, 0, "Name: %s\r\n\r\n", user->name);
if (length < 0) {
perror("snprintf");
exit(1);
}
char* output = malloc(length + 1);
if (output == NULL) {
perror("malloc");
exit(1);
}
length = strlen(output);
length += snprintf(output + length, strlen("Friends:\r\n") + 1, "Friends:\r\n");
for (int i = 0; i < MAX_FRIENDS && user->friends[i] != NULL; i++) {
length += snprintf(output + length, strlen(user->friends[i]->name) + strlen("\r\n") + 1, "%s\r\n", user->friends[i]->name);
}
length += snprintf(output + length, strlen("------------------------------------------\r\n") + 1, "------------------------------------------\r\n");
length += snprintf(output + length, strlen("Posts:\r\n") + 1, "Posts:\r\n");
const Post* curr = user->first_post;
while (curr != NULL) {
char* post_output = print_post(curr);
if (post_output != NULL) {
length += snprintf(output + length, strlen(post_output) + 1, "%s", post_output);
free(post_output);
}
curr = curr->next;
if (curr != NULL) {
length += snprintf(output + length, strlen("\r\n===\r\n\r\n") + 1, "\r\n===\r\n\r\n");
}
}
length += snprintf(output + length, strlen("------------------------------------------\r\n") + 1, "------------------------------------------\r\n");
return output;
} | null | null |
63c647855f004bf4898cf478 | 2023-01-17T20:06:50.584Z | General Question | v1 | fix my code
| null | null | null |
63c647875f004bf4898cf487 | 2023-01-30T06:04:39.369Z | Help Fix Code | v1 | null | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
// TODO: Process command line arguments.
if (!check_permissions(argv[1], argv[2])) {
printf("working\n");
}
char *first;
char *second;
scanf("%s %s", first, second);
printf("%s %s\n", first, second);
scanf("%s %s", first, second);
printf("%s %s\n", first, second);
scanf("%s %s", first, second);
printf("%s %s\n", first, second);
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
return 0;
} | no segmentation fault
| null |
63c647875f004bf4898cf487 | 2023-01-30T06:05:19.983Z | General Question | v1 | do you have to initialize strings
| null | null | null |
63c647875f004bf4898cf487 | 2023-01-30T06:05:53.424Z | General Question | v1 | why can't i use scanf to write to a string if i did not initialize the string | null | null | null |
63c647895f004bf4898cf496 | 2023-01-27T01:22:51.532Z | Help Fix Code | v1 | null | void fib(int** sequence, int n){
*sequence = malloc(sizeof(int) * n);
*sequence[0] = 0;
} | this is supposed to be a pointer to a pointer to a list of integers. but i keep getting a segmentation fault.
| null |
63c647895f004bf4898cf496 | 2023-01-27T01:42:16.047Z | Help Fix Code | v1 | null | void fib(int** sequence, int n){
sequence = (int) malloc(sizeof(int) * n);
(*sequence)[0] = 0;
(*sequence)[1] = 1;
for(int i = 2; i<n; i++){
(*sequence)[i] = (*sequence)[i-1] + (*sequence)[i-2];
}
}
int main(int argc, char **argv) {
int count = strtol(argv[1], NULL, 10);
int *fib_sequence;
fib(&fib_sequence, count);
for (int i = 0; i < count; i++) {
printf("%d ", fib_sequence[i]);
}
free(fib_sequence);
return 0;
} | I keep getting a segmentation error
| null |
63c647895f004bf4898cf496 | 2023-01-27T01:44:16.716Z | Explain Code | v1 | null | void fib(int** sequence, int n){
sequence = (int) malloc(sizeof(int) * n);
(*sequence)[0] = 0;
(*sequence)[1] = 1;
for(int i = 2; i<n; i++){
(*sequence)[i] = (*sequence)[i-1] + (*sequence)[i-2];
}
}
int main(int argc, char **argv) {
int count = strtol(argv[1], NULL, 10);
int *fib_sequence;
fib(&fib_sequence, count);
for (int i = 0; i < count; i++) {
printf("%d ", fib_sequence[i]);
}
free(fib_sequence);
return 0;
} | null | null |
63c647895f004bf4898cf496 | 2023-01-27T01:47:22.850Z | Help Fix Code | v1 | null | void fib(int** sequence, int n){
sequence = (int) malloc(sizeof(int) * n);
(*sequence)[0] = 0;
(*sequence)[1] = 1;
for(int i = 2; i<n; i++){
(*sequence)[i] = (*sequence)[i-1] + (*sequence)[i-2];
}
}
int main(int argc, char **argv) {
int count = strtol(argv[1], NULL, 10);
int *fib_sequence;
fib(&fib_sequence, count);
for (int i = 0; i < count; i++) {
printf("%d ", fib_sequence[i]);
}
free(fib_sequence);
return 0;
} | Can you show me what is causing the segmentation errors
| null |