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
⌀ |
---|---|---|---|---|---|---|---|
63c647fb5f004bf4898cf865 | 2023-02-14T08:24:39.505Z | Question from Code | v1 | where is memory leaking | #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(strlen(name) >= MAX_NAME){
return 2;
}
User *new_node = malloc(sizeof(User));
strcpy(new_node->name, name);
new_node->first_post = NULL;
for(int i = 0; i < MAX_FRIENDS; i++){
(new_node->friends)[i] = NULL;
}
new_node->next = NULL;
if(user_ptr_add[0] == NULL){
user_ptr_add[0] = new_node;
} else {
User *curr = user_ptr_add[0];
while(curr->next != NULL){
if(strcmp((*curr).name, name) == 0){
return 1;
free(new_node);
} else {
curr = curr->next;
}
}
if(strcmp((*curr).name, name) == 0){
return 1;
free(new_node);
} else {
curr->next = new_node;
}
}
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 *user_head = (User *) head;
if(user_head == NULL){
return NULL;
} else {
User *curr = user_head;
while(curr->next != NULL){
if(strcmp((*curr).name, name) == 0){
return curr;
} else {
curr = curr->next;
}
}
if(strcmp((*curr).name, name) == 0){
return curr;
}
}
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) {
User *user_curr = (User *) curr;
printf("%s\n", "User List");
if(user_curr == NULL){
;
} else {
User curr_user = user_curr[0];
while(curr_user.next != NULL){
printf("\t%s\n", curr_user.name);
curr_user = *(curr_user.next);
}
printf("\t%s\n", curr_user.name);
}
}
/*
* 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) {
if(strlen(filename) >= MAX_NAME){
return 2;
} else {
FILE *pic = fopen(filename, "r");
if(pic == NULL){
return 1;
} else {
fclose(pic);
strcpy(user->profile_pic, filename);
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 = find_user(name1, head);
User *user2 = find_user(name2, head);
if((find_user(name1, head) == NULL) || (find_user(name2, head) == NULL)){
return 4;
} else if(strcmp(name1, name2) == 0){
return 3;
} else {
for(int i = 0; i < MAX_FRIENDS; i++){
if((user1->friends)[i] == user2){
return 1;
}
}
int not_max = 0;
for(int i = 0; i < MAX_FRIENDS; i++){
if((user1->friends)[i] == NULL){
not_max = 1;
}
}
for(int i = 0; i < MAX_FRIENDS; i++){
if((user2->friends)[i] == NULL){
not_max = 1;
}
}
if(not_max==0){
return 2;
}
for(int i = 0; i < MAX_FRIENDS; i++){
if((user1->friends)[i] == NULL){
(user1->friends)[i] = user2;
break;
}
}
for(int i = 0; i < MAX_FRIENDS; i++){
if((user2->friends)[i] == NULL){
(user2->friends)[i] = user1;
break;
}
}
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;
} else {
if(user->profile_pic != NULL){
FILE *pic_file;
char line[100];
pic_file = fopen(user->profile_pic, "r");
if (pic_file != NULL){
while (fgets(line, 100, pic_file) != NULL) {
printf("%s", line);
}
fclose(pic_file);
printf("\n");
}
}
printf("%s%s\n", "Name: ", user->name);
printf("%s\n", "------------------------------------------");
printf("%s\n", "Friends:");
for(int i = 0; i < MAX_FRIENDS; i++){
if((user->friends)[i] != NULL){
printf("%s\n", ((user->friends)[i])->name);
}
}
printf("%s\n", "------------------------------------------");
printf("%s\n", "Posts:");
if(user->first_post == NULL){
;
} else {
Post *curr_post = (user->first_post);
while(curr_post->next != NULL){
printf("%s%s\n", "From: ", curr_post->author);
printf("%s%s\n", "Date: ", ctime(curr_post->date));
printf("%s\n", curr_post->contents);
printf("\n%s\n\n", "===");
curr_post = curr_post->next;
}
printf("%s%s\n", "From: ", curr_post->author);
printf("%s%s\n", "Date: ", ctime(curr_post->date));
printf("%s\n", curr_post->contents);
}
printf("%s\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;
} else {
int friends = 0;
for(int i = 0; i < MAX_FRIENDS; i++){
if((author->friends)[i] == target){
friends = 1;
}
}
if(friends == 0){
return 1;
}
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
time_t *post_time = malloc(sizeof(time_t));
*post_time = time(NULL);
new_post->date = post_time;
new_post->next = target->first_post;
target->first_post = new_post;
return 0;
}
}
/*
* 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[0]) == NULL){
return 1;
} else {
User *user_to_delete = find_user(name, user_ptr_del[0]);
//remove as friend
for(int i = 0; i < MAX_FRIENDS; i++){
if((user_to_delete->friends)[i] != NULL){
User *friend_user = find_user((user_to_delete->friends)[i]->name, user_ptr_del[0]);
for(int i = 0; i < MAX_FRIENDS; i++){
if(((friend_user->friends)[i] != NULL) && (friend_user->friends)[i] == user_to_delete){
friend_user->friends[i] = NULL;
}
}
}
}
//delete the user from the linked list
User *curr = user_ptr_del[0];
while((curr->next != NULL) && (curr->next) != user_to_delete){
curr = curr->next;
}
curr->next = user_to_delete->next;
//free all memory related to the user
Post *curr_post = user_to_delete->first_post;
while(curr_post != NULL){
free(curr_post->contents);
free(curr_post->date);
free(curr_post);
curr_post = curr_post->next;
}
free(user_to_delete);
return 0;
}
} | null | null |
63c647fb5f004bf4898cf865 | 2023-02-15T05:50:48.176Z | General Question | v1 | tons of valgrind error makes valgrind stuck and does not show me heap summary. what to do. | null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-15T06:03:11.631Z | 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) {
//checking if given name cannot fit in name array
if(strlen(name) >= MAX_NAME){
return 2;
}
User *new_node = malloc(sizeof(User));
strcpy(new_node->name, name);
new_node->first_post = NULL;
for(int i = 0; i < MAX_FRIENDS; i++){
(new_node->friends)[i] = NULL;
}
new_node->next = NULL;
if(user_ptr_add[0] == NULL){
user_ptr_add[0] = new_node;
} else {
User *curr = user_ptr_add[0];
while(curr->next != NULL){
if(strcmp((*curr).name, name) == 0){
return 1;
free(new_node);
} else {
curr = curr->next;
}
}
if(strcmp((*curr).name, name) == 0){
return 1;
free(new_node);
} else {
curr->next = new_node;
}
}
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 *user_head = (User *) head;
if(user_head == NULL){
return NULL;
} else {
User *curr = user_head;
while(curr->next != NULL){
if(strcmp((*curr).name, name) == 0){
return curr;
} else {
curr = curr->next;
}
}
if(strcmp((*curr).name, name) == 0){
return curr;
}
}
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) {
User *user_curr = (User *) curr;
printf("%s\n", "User List");
if(user_curr == NULL){
;
} else {
User curr_user = user_curr[0];
while(curr_user.next != NULL){
printf("\t%s\n", curr_user.name);
curr_user = *(curr_user.next);
}
printf("\t%s\n", curr_user.name);
}
}
/*
* 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) {
if(strlen(filename) >= MAX_NAME){
return 2;
} else {
FILE *pic = fopen(filename, "r");
if(pic == NULL){
return 1;
} else {
fclose(pic);
strcpy(user->profile_pic, filename);
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 = find_user(name1, head);
User *user2 = find_user(name2, head);
if((find_user(name1, head) == NULL) || (find_user(name2, head) == NULL)){
return 4;
} else if(strcmp(name1, name2) == 0){
return 3;
} else {
for(int i = 0; i < MAX_FRIENDS; i++){
if((user1->friends)[i] == user2){
return 1;
}
}
int not_max_user1 = 0;
int not_max_user2 = 0;
for(int i = 0; i < MAX_FRIENDS; i++){
if((user1->friends)[i] == NULL){
not_max_user1 = 1;
}
}
for(int i = 0; i < MAX_FRIENDS; i++){
if((user2->friends)[i] == NULL){
not_max_user2 = 1;
}
}
if((not_max_user1==0) || (not_max_user2)==0 ){
return 2;
}
for(int i = 0; i < MAX_FRIENDS; i++){
if((user1->friends)[i] == NULL){
(user1->friends)[i] = user2;
break;
}
}
for(int i = 0; i < MAX_FRIENDS; i++){
if((user2->friends)[i] == NULL){
(user2->friends)[i] = user1;
break;
}
}
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;
} else {
if(user->profile_pic != NULL){
FILE *pic_file;
char line[100];
pic_file = fopen(user->profile_pic, "r");
if (pic_file != NULL){
while (fgets(line, 100, pic_file) != NULL) {
printf("%s", line);
}
fclose(pic_file);
printf("\n");
}
}
printf("%s%s\n", "Name: ", user->name);
printf("%s\n", "------------------------------------------");
printf("%s\n", "Friends:");
for(int i = 0; i < MAX_FRIENDS; i++){
if((user->friends)[i] != NULL){
printf("%s\n", ((user->friends)[i])->name);
}
}
printf("%s\n", "------------------------------------------");
printf("%s\n", "Posts:");
if(user->first_post == NULL){
;
} else {
Post *curr_post = (user->first_post);
while(curr_post->next != NULL){
printf("%s%s\n", "From: ", curr_post->author);
printf("%s%s\n", "Date: ", ctime(curr_post->date));
printf("%s\n", curr_post->contents);
printf("\n%s\n\n", "===");
curr_post = curr_post->next;
}
printf("%s%s\n", "From: ", curr_post->author);
printf("%s%s\n", "Date: ", ctime(curr_post->date));
printf("%s\n", curr_post->contents);
}
printf("%s\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;
} else {
int friends = 0;
for(int i = 0; i < MAX_FRIENDS; i++){
if((author->friends)[i] == target){
friends = 1;
}
}
if(friends == 0){
return 1;
}
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
time_t *post_time = malloc(sizeof(time_t));
*post_time = time(NULL);
new_post->date = post_time;
new_post->next = target->first_post;
target->first_post = new_post;
return 0;
}
}
/*
* 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[0]) == NULL){
return 1;
} else {
User *user_to_delete = find_user(name, user_ptr_del[0]);
//remove as friend
for(int i = 0; i < MAX_FRIENDS; i++){
if((user_to_delete->friends)[i] != NULL){
User *friend_user = find_user((user_to_delete->friends)[i]->name, user_ptr_del[0]);
for(int i = 0; i < MAX_FRIENDS; i++){
if(((friend_user->friends)[i] != NULL) && (friend_user->friends)[i] == user_to_delete){
friend_user->friends[i] = NULL;
}
}
}
}
//delete the user from the linked list
User *curr = user_ptr_del[0];
if(curr->next == NULL){
user_ptr_del[0] = NULL;
} else {
while((curr->next != NULL) && ((curr->next) != user_to_delete)){
curr = curr->next;
}
curr->next = user_to_delete->next;
}
//free all memory related to the user
Post *curr_post = user_to_delete->first_post;
while(curr_post != NULL){
free(curr_post->contents);
free(curr_post->date);
free(curr_post);
curr_post = curr_post->next;
}
free(user_to_delete);
return 0;
}
} | need to fix multiple invalid read erros | null |
63c647fb5f004bf4898cf865 | 2023-02-15T06:04:26.232Z | Question from Code | v1 | how to fix multiple invalid read erros | #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) {
//checking if given name cannot fit in name array
if(strlen(name) >= MAX_NAME){
return 2;
}
User *new_node = malloc(sizeof(User));
strcpy(new_node->name, name);
new_node->first_post = NULL;
for(int i = 0; i < MAX_FRIENDS; i++){
(new_node->friends)[i] = NULL;
}
new_node->next = NULL;
if(user_ptr_add[0] == NULL){
user_ptr_add[0] = new_node;
} else {
User *curr = user_ptr_add[0];
while(curr->next != NULL){
if(strcmp((*curr).name, name) == 0){
return 1;
free(new_node);
} else {
curr = curr->next;
}
}
if(strcmp((*curr).name, name) == 0){
return 1;
free(new_node);
} else {
curr->next = new_node;
}
}
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 *user_head = (User *) head;
if(user_head == NULL){
return NULL;
} else {
User *curr = user_head;
while(curr->next != NULL){
if(strcmp((*curr).name, name) == 0){
return curr;
} else {
curr = curr->next;
}
}
if(strcmp((*curr).name, name) == 0){
return curr;
}
}
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) {
User *user_curr = (User *) curr;
printf("%s\n", "User List");
if(user_curr == NULL){
;
} else {
User curr_user = user_curr[0];
while(curr_user.next != NULL){
printf("\t%s\n", curr_user.name);
curr_user = *(curr_user.next);
}
printf("\t%s\n", curr_user.name);
}
}
/*
* 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) {
if(strlen(filename) >= MAX_NAME){
return 2;
} else {
FILE *pic = fopen(filename, "r");
if(pic == NULL){
return 1;
} else {
fclose(pic);
strcpy(user->profile_pic, filename);
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 = find_user(name1, head);
User *user2 = find_user(name2, head);
if((find_user(name1, head) == NULL) || (find_user(name2, head) == NULL)){
return 4;
} else if(strcmp(name1, name2) == 0){
return 3;
} else {
for(int i = 0; i < MAX_FRIENDS; i++){
if((user1->friends)[i] == user2){
return 1;
}
}
int not_max_user1 = 0;
int not_max_user2 = 0;
for(int i = 0; i < MAX_FRIENDS; i++){
if((user1->friends)[i] == NULL){
not_max_user1 = 1;
}
}
for(int i = 0; i < MAX_FRIENDS; i++){
if((user2->friends)[i] == NULL){
not_max_user2 = 1;
}
}
if((not_max_user1==0) || (not_max_user2)==0 ){
return 2;
}
for(int i = 0; i < MAX_FRIENDS; i++){
if((user1->friends)[i] == NULL){
(user1->friends)[i] = user2;
break;
}
}
for(int i = 0; i < MAX_FRIENDS; i++){
if((user2->friends)[i] == NULL){
(user2->friends)[i] = user1;
break;
}
}
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;
} else {
if(user->profile_pic != NULL){
FILE *pic_file;
char line[100];
pic_file = fopen(user->profile_pic, "r");
if (pic_file != NULL){
while (fgets(line, 100, pic_file) != NULL) {
printf("%s", line);
}
fclose(pic_file);
printf("\n");
}
}
printf("%s%s\n", "Name: ", user->name);
printf("%s\n", "------------------------------------------");
printf("%s\n", "Friends:");
for(int i = 0; i < MAX_FRIENDS; i++){
if((user->friends)[i] != NULL){
printf("%s\n", ((user->friends)[i])->name);
}
}
printf("%s\n", "------------------------------------------");
printf("%s\n", "Posts:");
if(user->first_post == NULL){
;
} else {
Post *curr_post = (user->first_post);
while(curr_post->next != NULL){
printf("%s%s\n", "From: ", curr_post->author);
printf("%s%s\n", "Date: ", ctime(curr_post->date));
printf("%s\n", curr_post->contents);
printf("\n%s\n\n", "===");
curr_post = curr_post->next;
}
printf("%s%s\n", "From: ", curr_post->author);
printf("%s%s\n", "Date: ", ctime(curr_post->date));
printf("%s\n", curr_post->contents);
}
printf("%s\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;
} else {
int friends = 0;
for(int i = 0; i < MAX_FRIENDS; i++){
if((author->friends)[i] == target){
friends = 1;
}
}
if(friends == 0){
return 1;
}
Post *new_post = malloc(sizeof(Post));
strcpy(new_post->author, author->name);
new_post->contents = contents;
time_t *post_time = malloc(sizeof(time_t));
*post_time = time(NULL);
new_post->date = post_time;
new_post->next = target->first_post;
target->first_post = new_post;
return 0;
}
}
/*
* 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[0]) == NULL){
return 1;
} else {
User *user_to_delete = find_user(name, user_ptr_del[0]);
//remove as friend
for(int i = 0; i < MAX_FRIENDS; i++){
if((user_to_delete->friends)[i] != NULL){
User *friend_user = find_user((user_to_delete->friends)[i]->name, user_ptr_del[0]);
for(int i = 0; i < MAX_FRIENDS; i++){
if(((friend_user->friends)[i] != NULL) && (friend_user->friends)[i] == user_to_delete){
friend_user->friends[i] = NULL;
}
}
}
}
//delete the user from the linked list
User *curr = user_ptr_del[0];
if(curr->next == NULL){
user_ptr_del[0] = NULL;
} else {
while((curr->next != NULL) && ((curr->next) != user_to_delete)){
curr = curr->next;
}
curr->next = user_to_delete->next;
}
//free all memory related to the user
Post *curr_post = user_to_delete->first_post;
while(curr_post != NULL){
free(curr_post->contents);
free(curr_post->date);
free(curr_post);
curr_post = curr_post->next;
}
free(user_to_delete);
return 0;
}
} | null | null |
63c647fb5f004bf4898cf865 | 2023-02-15T06:53:27.359Z | General Question | v1 | how to use gdb to debug | null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-15T17:36:02.025Z | General Question | v1 | when i intialise char *profile, what is its default value set to | null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-15T20:39:40.750Z | General Question | v1 | how to check if malloc fails | null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-15T22:18:42.626Z | General Question | v1 | what is memset | null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-16T19:21:12.396Z | General Question | v1 | c_helper.py:125: in _t
stdout, stderr, returncode = self._run_exec(args=args, input_=input_, timeout=timeout)
c_helper.py:85: in _run_exec
return _exec([os.path.join(".", self.executable_name)] + (args or []), **kwargs)
c_helper.py:471: in _exec
stdout, stderr = proc.communicate(timeout=timeout, input=input_)
/local/packages/python-3.10/lib/python3.10/subprocess.py:1152: in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
/local/packages/python-3.10/lib/python3.10/subprocess.py:2041: in _communicate
stdout = self._translate_newlines(stdout,
/local/packages/python-3.10/lib/python3.10/subprocess.py:1029: in _translate_newlines
data = data.decode(encoding, errors)
E UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfd in position 4: invalid start byte
WHAT IS THIS ERROR? | null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-17T20:49:07.750Z | General Question | v1 | strncpy(char *dest, "ananyajain", 7) output? | null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-24T04:22:09.710Z | Question from Code | v1 | what is the output of the code | #include <stdio.h>
#include <stdlib.h>
// Initialize two parallel lists.
void initialize(int *a1, int *a2, int n) {
for (int i = 0; i < n; i++) {
a1[i] = i;
a2[i] = i;
}
}
int main() {
int numbers1[3];
int *numbers2 = malloc(sizeof(int) * 3);
initialize(numbers1, numbers2, 3);
for (int i = 0; i < 3; i++) {
printf("%d %d\n",
numbers1[i], numbers2[i]);
}
free(numbers2);
return 0;
} | null | null |
63c647fb5f004bf4898cf865 | 2023-02-25T01:12:08.982Z | General Question | v1 | what exactly is the second parameter of strtol
| null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-25T01:20:27.479Z | Question from Code | v1 | what is strlen(a) | char *a = "Hello I" | null | null |
63c647fb5f004bf4898cf865 | 2023-02-25T01:21:28.920Z | General Question | v1 | is strlen(a) 7 or 8 or 9
| null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-25T01:21:55.847Z | Question from Code | v1 | is strlen(a) 7 or 8 or 9 | char *a = "Hello I" | null | null |
63c647fb5f004bf4898cf865 | 2023-02-25T01:22:23.216Z | General Question | v1 | what is strlen(a) when char *a = "Hello I" | null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-28T13:42:36.004Z | Question from Code | v1 | what will be the output | char *a = "Hello Bruh"
char *b = strchr(a, ' ')
printf("%s", b) | null | null |
63c647fb5f004bf4898cf865 | 2023-02-28T13:43:12.003Z | Question from Code | v1 | output | char *a = "Hello Bruh"
char *b = strchr(a, ' ') - 1
printf("%s", b) | null | null |
63c647fb5f004bf4898cf865 | 2023-02-28T13:43:40.890Z | Question from Code | v1 | output | char *a = "Hello Bruh"
char *b = strchr(a, ' ') - 2
printf("%s", b) | null | null |
63c647fb5f004bf4898cf865 | 2023-02-28T13:57:12.514Z | General Question | v1 | how does grep work
| null | null | null |
63c647fb5f004bf4898cf865 | 2023-02-28T13:58:07.770Z | General Question | v1 | how does cut work | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-08T20:59:08.860Z | General Question | v1 | my child calls a different program using execl which has different exit values. how do i get the exit value the program exited with back to my child | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-09T17:39:55.883Z | General Question | v2 | how to write "swim" to stdin
| null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-09T17:45:14.359Z | General Question | v2 | a program called validate is expecting 2 inputs from stdin. my function calls validate using execl. how do i pass the variables i need to as stdin to it. | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-09T19:54:51.918Z | General Question | v2 | what is the difference between exit(0) and return 0 | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-11T00:46:58.582Z | General Question | v2 | how does strtok work | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-11T01:23:26.533Z | General Question | v2 | Let a string be s = "main : linked_list.o main.o". What is the output of strtok(s, " ") | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-11T01:35:30.566Z | General Question | v2 | how to check is a string starts with \t | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-11T01:37:30.028Z | Question from Code | v2 | what is the value of b | a = "\tHello World" b = strncmp(a, "\t", 1);
| null | null |
63c647fb5f004bf4898cf865 | 2023-03-11T06:30:58.170Z | Question from Code | v2 | what is the value of token | char *a = "\tHello Boss" char *token = strtok(a, " ")
| null | null |
63c647fb5f004bf4898cf865 | 2023-03-11T07:02:24.286Z | General Question | v2 | what does strncmp returning 3 mean | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-11T18:36:25.133Z | General Question | v2 | how to find if a char is in a string
| null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-13T17:16:17.258Z | Question from Code | v2 | what is the value of a[0] | char *a = "Hello I am Kaavya"; | null | null |
63c647fb5f004bf4898cf865 | 2023-03-13T17:19:27.142Z | General Question | v2 | how does stat work? | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-13T20:54:27.091Z | General Question | v2 | how to use access to check if a file exists or not | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-13T22:23:42.855Z | General Question | v2 | how to check if a string is NULL | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-14T06:59:19.696Z | Question from Code | v2 | what is return value of args_to_string({"Hi" , "Kaavya" , NULL}, a, 3 | char *args_to_string(char **args, char *buffer, int size) {
buffer[0] = '\0';
int i = 0;
while (args[i] != NULL) {
strncat(buffer, args[i], size - strlen(buffer));
strncat(buffer, " ", size - strlen(buffer));
i++;
}
return buffer;
}
char *a = malloc(256);
| null | null |
63c647fb5f004bf4898cf865 | 2023-03-14T07:00:09.491Z | Question from Code | v2 | what is return value of args_to_string({"Hi" , "Kaavya" , NULL}, a, 256) | char *args_to_string(char **args, char *buffer, int size) {
buffer[0] = '\0';
int i = 0;
while (args[i] != NULL) {
strncat(buffer, args[i], size - strlen(buffer));
strncat(buffer, " ", size - strlen(buffer));
i++;
}
return buffer;
}
char *a = malloc(256);
| null | null |
63c647fb5f004bf4898cf865 | 2023-03-14T07:07:45.074Z | General Question | v2 | how to update the updated time of a file
| null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-14T07:45:21.157Z | General Question | v2 | Can you use variables declared in the main stack directly in a function and change its value globally (variable of type int) | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-15T05:54:19.022Z | General Question | v2 | how to mention the start and end numbers for random() | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-17T02:07:41.161Z | General Question | v2 | how to use random() to generate numbers between 0 to 99 inclusive in C | null | null | null |
63c647fb5f004bf4898cf865 | 2023-03-17T02:08:26.512Z | Help Write Code | v2 | null | null | null | how to use random() to generate numbers between 0 to 99 inclusive in C |
63c647fb5f004bf4898cf865 | 2023-03-21T23:19:14.843Z | Question from Code | v2 | what is a[2] | char *a = "Hello" | null | null |
63c647fb5f004bf4898cf865 | 2023-03-26T01:23:35.472Z | Question from Code | v2 | why am i getting a \n in my msg | int read_from(int client_index, struct sockname *users) {
int fd = users[client_index].sock_fd;
char buf[BUF_SIZE + 1];
int num_read = read(fd, &buf, BUF_SIZE);
buf[num_read] = '\0';
if (users[client_index].username == NULL) {
if (num_read == 0) {
users[client_index].sock_fd = -1;
return fd;
}
users[client_index].username = malloc(num_read + 1);
strncpy(users[client_index].username, buf, num_read + 1);
return 0;
}
if (num_read == 0 || write(fd, buf, strlen(buf)) != strlen(buf)) {
users[client_index].sock_fd = -1;
return fd;
}
char *msg = malloc(num_read + 3 + strlen(users[client_index].username));
sprintf(msg, "%s: %s", users[client_index].username, buf);
for (int i = 0; i < MAX_CONNECTIONS; i++) {
if (users[i].sock_fd != -1) {
write(users[i].sock_fd, msg, strlen(msg));
}
}
free(msg);
return 0;
} | null | null |
63c647fb5f004bf4898cf865 | 2023-03-27T04:40:39.790Z | General Question | v2 | area=`expr $width * $height`
why is this incorrect | null | null | null |
63c647fb5f004bf4898cf865 | 2023-04-04T22:59:31.345Z | Question from Code | v2 | does the given code work | char *a;
a = "Hello"; | null | null |
63c647fb5f004bf4898cf86a | 2023-01-25T01:44:10.416Z | General Question | v1 | How do I reassign a string in C | null | null | null |
63c647fb5f004bf4898cf86a | 2023-01-25T02:15:37.567Z | General Question | v1 | How do I read a file through stdin in C | null | null | null |
63c647fb5f004bf4898cf86a | 2023-01-25T02:16:54.510Z | General Question | v1 | How do I use scanf to read a redirected file | null | null | null |
63c647fb5f004bf4898cf86a | 2023-01-25T15:05:23.024Z | General Question | v1 | How do I use a function in one C file in another C file | null | null | null |
63c647fb5f004bf4898cf86a | 2023-01-25T15:22:01.497Z | General Question | v1 | How to convert char to int | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-07T15:40:50.302Z | General Question | v1 | split string on spaces
| null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-07T15:49:59.570Z | General Question | v1 | how do i read a file line by line | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-07T16:11:49.425Z | General Question | v1 | read character by character in a string | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-07T16:15:41.136Z | General Question | v1 | does fgets overwrite the string array | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-07T16:44:26.728Z | General Question | v1 | dictionaries in C | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-07T17:14:22.595Z | General Question | v1 | count number of spaces in string
| null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-07T20:50:40.799Z | General Question | v1 | how to read the last string in a string delimeted by a delimeter using strtok | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-07T21:30:51.805Z | Question from Code | v1 | strtok doesnt work as expected, last string in line cannot be obtained
| //get the target name
targets = strtok(line, " ");
printf("%s \n", targets);
//create the Rule datatype
if (curr_rule == NULL){
curr_rule = malloc(sizeof(Rule));
head = curr_rule;
}else{
Rule * new_rule = malloc(sizeof(Rule));
(curr_rule -> next_rule) = new_rule;
curr_rule = new_rule;
}
curr_rule -> next_rule = NULL;
//set the name properly
(curr_rule -> target) = malloc(sizeof(char) * (strlen(targets) + 1));
strncpy(curr_rule -> target, targets, sizeof(char) * (strlen(targets) + 1));
(curr_rule -> target)[strlen(curr_rule -> target)] = '\0';
//link the dependencies
targets = strtok(NULL, " ");
while (targets != NULL){
printf("%s \n", targets);
targets = strtok(NULL, " ");
if (targets != NULL){
link_dependencies(targets, curr_dependency, head);
}
} | null | null |
63c647fc5f004bf4898cf874 | 2023-03-07T21:31:42.917Z | Explain Code | v1 | null | //get the target name
targets = strtok(line, " ");
printf("%s \n", targets);
//create the Rule datatype
if (curr_rule == NULL){
curr_rule = malloc(sizeof(Rule));
head = curr_rule;
}else{
Rule * new_rule = malloc(sizeof(Rule));
(curr_rule -> next_rule) = new_rule;
curr_rule = new_rule;
}
curr_rule -> next_rule = NULL;
//set the name properly
(curr_rule -> target) = malloc(sizeof(char) * (strlen(targets) + 1));
strncpy(curr_rule -> target, targets, sizeof(char) * (strlen(targets) + 1));
(curr_rule -> target)[strlen(curr_rule -> target)] = '\0';
//link the dependencies
targets = strtok(NULL, " ");
while (targets != NULL){
printf("%s \n", targets);
targets = strtok(NULL, " ");
if (targets != NULL){
link_dependencies(targets, curr_dependency, head);
}
} | null | null |
63c647fc5f004bf4898cf874 | 2023-03-08T17:48:54.125Z | General Question | v1 | skip the first character in a string literal
| null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-09T17:41:38.147Z | General Question | v2 | print a char** array | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-09T17:53:26.927Z | General Question | v2 | how does recursion work in C? | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-09T18:09:05.366Z | General Question | v2 | how do i make my function wait on a recursive call without using fork in C? | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-14T22:36:12.789Z | General Question | v2 | how do i use random in C? it says it need RAND_MAX, how do i set it myself? | null | null | null |
63c647fc5f004bf4898cf874 | 2023-03-14T23:05:10.130Z | Question from Code | v2 | not reading binary file correctly. giving me random values. |
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#define MESSAGE "%ld reads were done in %ld seconds.\n"
long num_reads, seconds;
int main(int argc, char **argv) {
if (argc != 3) {
fprintf(stderr, "Usage: time_reads s filename\n");
exit(1);
}
seconds = strtol(argv[1], NULL, 10);
FILE *fp;
if ((fp = fopen(argv[2], "r")) == NULL) {
perror("fopen");
exit(1);
}
int rand_idx;
int value_at_idx;
for (int i = 0; i < 100; i++) {
rand_idx = (int)(((double)random() / RAND_MAX) * 99);
fseek(fp, rand_idx, SEEK_SET);
fread(&value_at_idx, sizeof(int), 1, fp);
printf("%i\n", value_at_idx);
}
return 1;
}
| null | null |
63c647fc5f004bf4898cf874 | 2023-03-27T16:33:22.584Z | General Question | v2 | I am unable to use asprintf, eventhough i have defined _GNU_SOURCE and imported stdio.h | null | null | null |
63c647fd5f004bf4898cf879 | 2023-01-31T19:42:37.938Z | General Question | v1 | Is the function strcpy safe? | null | null | null |
63c647fd5f004bf4898cf879 | 2023-01-31T19:45:48.601Z | General Question | v1 | How to copy a string to an array of char in C safely? | null | null | null |
63c647ff5f004bf4898cf888 | 2023-01-23T22:55:59.232Z | Help Fix Code | v1 | null | hile (scanf(" %c %s %*d %*s %*s %d %*s %*d %*s %*s", &file_type, permissions, &file_size) != EOF) { | null | null |
63c647ff5f004bf4898cf888 | 2023-01-23T22:56:43.380Z | Help Fix Code | v1 | null | while (scanf(" %c %s %*d %*s %*s %d %*s %*d %*s %*s", &file_type, permissions, &file_size) != EOF) {scanf(" %s %d ", temp_s, &temp_i);
while (scanf(" %c %s %*d %*s %*s %d %*s %*d %*s %*s ", &file_type, permissions, &file_size) != EOF) {
if (file_type == '-' && file_size > cutoff_size) {
if (argc == 2){
count_so_far++;
} else {
if (check_permissions(permissions, argv[2]) == 0) {
count_so_far++;
}
}
}
} | null | null |
63c647ff5f004bf4898cf888 | 2023-01-23T22:57:20.101Z | Help Fix Code | v1 | null |
while (scanf(" %c %s %*d %*s %*s %d %*s %*d %*s %*s ", &file_type, permissions, &file_size) != EOF) {
if (file_type == '-' && file_size > cutoff_size) {
if (argc == 2){
count_so_far++;
} else {
if (check_permissions(permissions, argv[2]) == 0) {
count_so_far++;
}
}
}
} | null | null |
63c647ff5f004bf4898cf888 | 2023-01-23T22:57:51.510Z | Question from Code | v1 | why should I put a space after the last %*s
|
while (scanf(" %c %s %*d %*s %*s %d %*s %*d %*s %*s ", &file_type, permissions, &file_size) != EOF) {
if (file_type == '-' && file_size > cutoff_size) {
if (argc == 2){
count_so_far++;
} else {
if (check_permissions(permissions, argv[2]) == 0) {
count_so_far++;
}
}
}
} | null | null |
63c647ff5f004bf4898cf88d | 2023-01-17T23:44:24.128Z | Explain Code | v1 | null | int age[5] = {4, 70, 52, 18, 16};
int *p = age; | null | null |
63c648025f004bf4898cf89c | 2023-01-17T22:01:24.007Z | Question from Code | v1 | Why is phone used instead of &phone? | char phone[11];
scanf("%s %d", phone, &index); | null | null |
63c648025f004bf4898cf89c | 2023-01-17T22:03:09.890Z | Help Fix Code | v1 | null | char phone[11];
scanf("%s %d", &phone); | get string input and store it in phone. | null |
63c648055f004bf4898cf8bf | 2023-01-23T03:55:47.480Z | General Question | v1 | why is system("ls -l") of type int? | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T04:38:30.199Z | General Question | v1 | does scanf read multiple lines? | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T04:47:59.292Z | Question from Code | v1 | how do I only print certain part of stdin? | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
if (argc == 2) {
char line[32];
while (fgets(line, 32, stdin) != NULL) {
printf("%s", line);
}
}
return 0;
} | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T04:48:43.044Z | Question from Code | v1 | how do i parse stdin without strtok? | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
if (argc == 2) {
char line[32];
while (fgets(line, 32, stdin) != NULL) {
printf("%s", line);
}
}
return 0;
} | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T04:49:13.072Z | Question from Code | v1 | how do i parse stdin with strtol? | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
if (argc == 2) {
char line[32];
while (fgets(line, 32, stdin) != NULL) {
printf("%s", line);
}
}
return 0;
} | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T04:52:42.686Z | Question from Code | v1 | inputs of scanf? | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
if (argc == 2) {
char line[32];
while (fgets(line, 32, stdin) != NULL) {
printf("%s", line);
}
}
return 0;
} | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T04:53:44.548Z | General Question | v1 | if my stdin is "hello yo 3 191 so what" what are my scanf arguments? | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T04:55:17.495Z | General Question | v1 | if my stdin is "-rwxrwxrwx 1 kimluci2 kimluci2 763 Jan 22 18:05 Makefile" what are my scanf arguments? | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T05:10:17.348Z | General Question | v1 | how do i skip the first line of stdin when scanf? | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T06:06:30.169Z | General Question | v1 | what is the type of %c%10s | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T06:10:45.967Z | General Question | v1 | how do i initialize a variable of %c%10s | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T06:12:41.383Z | General Question | v1 | is %c variable declared as char | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T06:27:52.509Z | Question from Code | v1 | what does EOF do | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
// TODO: Process command line arguments.
if (argc == 2) {
int total = 0;
char dir;
char perms[10];
int size;
int param1 = strtol(argv[1], NULL, 10);
while (scanf("%c%10s %*d %*s %*s %d %*s %*d %*s %*s\n", &dir, perms, &size) != EOF) {
if (size > param1) {
total += 1;
}
}
printf("%d\n", total);
}
return 0;
}
| null | null |
63c648055f004bf4898cf8bf | 2023-01-23T06:28:37.760Z | Question from Code | v1 | what does == 3 in the while loop do | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
// TODO: Process command line arguments.
if (argc == 2) {
int total = 0;
char dir;
char perms[10];
int size;
int param1 = strtol(argv[1], NULL, 10);
while (scanf("%c%10s %*d %*s %*s %d %*s %*d %*s %*s\n", &dir, perms, &size) == 3) {
if (size > param1) {
total += 1;
}
}
printf("%d\n", total);
}
return 0;
}
| null | null |
63c648055f004bf4898cf8bf | 2023-01-23T06:34:25.907Z | General Question | v1 | how do i make scanf ignore the first line? | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T06:35:03.922Z | Question from Code | v1 | how do i make scanf skip a specific line? | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
// TODO: Process command line arguments.
if (argc == 2) {
int total = 0;
char dir;
char perms[10];
int size;
int param1 = strtol(argv[1], NULL, 10);
while (scanf("%c%10s %*d %*s %*s %d %*s %*d %*s %*s\n", &dir, perms, &size) == 3) {
if (size > param1) {
total += 1;
}
}
printf("%d\n", total);
}
return 0;
}
| null | null |
63c648055f004bf4898cf8bf | 2023-01-23T06:37:45.311Z | General Question | v1 | %*[^\n] what does ths do | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T06:44:42.098Z | Question from Code | v1 | how do i ONLY skip the first line from stdin?? | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
// TODO: Process command line arguments.
if (argc == 2) {
int total = 0;
char dir;
char perms[10];
int size;
int param1 = strtol(argv[1], NULL, 10);
while (scanf("%*[^\n] %c%10s %*d %*s %*s %d %*s %*d %*s %*s\n", &dir, perms, &size) != EOF) {
if (size > param1) {
total += 1;
}
}
printf("%d\n", total);
}
// TODO: Call check_permissions as part of your solution to count the files to
// compute and print the correct value.
// if (arg == 3) {
// char test[32];
// scanf("%s", test);
// int result = check_permissions();
// printf("%d", result);
// }
return 0;
} | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T07:14:18.140Z | Question from Code | v1 | why is (dir == "-") giving me errors? | int main(int argc, char** argv) {
if (!(argc == 2 || argc == 3)) {
fprintf(stderr, "USAGE: count_large size [permissions]\n");
return 1;
}
// TODO: Process command line arguments.
if (argc == 2) {
int total = 0;
char dir;
char perms[10];
int size;
int param1 = strtol(argv[1], NULL, 10);
scanf("%*[^\n]\n");
while (scanf("%c%10s %*d %*s %*s %d %*s %*d %*s %*s\n", &dir, perms, &size) != EOF) {
if ((size > param1) && (dir == "-")) {
printf("%c\n", dir);
total += 1;
}
}
printf("%d\n", total);
}
return 0; | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T17:08:26.133Z | General Question | v1 | how to check a given integer is 9 digits using % 10 or / 10 | null | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T17:12:11.923Z | Question from Code | v1 | what does this return | int help = 100000000 % 10;
printf("%d", help); | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T17:12:47.748Z | Question from Code | v1 | what does this return | int help = 100923999 % 10;
printf("%d", help); | null | null |
63c648055f004bf4898cf8bf | 2023-01-23T17:13:38.461Z | General Question | v1 | how do i check that a given integer is 9 digits? | 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.