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
63c647895f004bf4898cf496
2023-02-03T07:26:44.950Z
Help Fix Code
v1
null
int truncate(char *target, int amt){ int leng = strlen(target); if (leng > amt){ return 0; } char result[45] = "abc" ; strncpy(result, target, amt); printf("This is the value of the truncated string: %s\n", result); return leng - amt ; }
supposed to take target and store the first amt characters in result.
null
63c647895f004bf4898cf496
2023-02-13T01:46:40.306Z
Help Fix Code
v1
null
int make_post(const User *author, User *target, char *contents) { if(author == NULL || target == NULL){ printf("Returning 2\n"); return 2; } //We only check in one list because we assume that make_friends works properly int flag = 0; for(int i=0; i<MAX_FRIENDS; i++){ if ((author->friends[i] != NULL) && (author->friends[i]->name == target->name)){ flag = 1; } } if(flag != 1){ //if flag == 1, then they are friends. So we return if != 1. return 1; } Post *newpost = malloc(sizeof(Post)); strcpy(newpost->author, author->name); newpost->contents = contents; time_t creation_time = time(NULL); *(newpost->date ) = creation_time; newpost->next = target->first_post; target->first_post = newpost; 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
63c647895f004bf4898cf496
2023-02-13T01:51:31.338Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; int make_post(const User *author, User *target, char *contents) { if(author == NULL || target == NULL){ printf("Returning 2\n"); return 2; } //We only check in one list because we assume that make_friends works properly int flag = 0; for(int i=0; i<MAX_FRIENDS; i++){ if ((author->friends[i] != NULL) && (author->friends[i]->name == target->name)){ flag = 1; } } if(flag != 1){ //if flag == 1, then they are friends. So we return if != 1. return 1; } Post *newpost = malloc(sizeof(Post)); strcpy(newpost->author, author->name); newpost->contents = contents; time_t creation_time = time(NULL); *(newpost->date ) = creation_time; newpost->next = target->first_post; target->first_post = newpost; return 0; }
problem with newpost->date;
null
63c647895f004bf4898cf496
2023-02-13T02:19:56.199Z
Help Fix Code
v1
null
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post; int make_post(const User *author, User *target, char *contents) { if(author == NULL || target == NULL){ printf("Returning 2\n"); return 2; } //We only check in one list because we assume that make_friends works properly int flag = 0; for(int i=0; i<MAX_FRIENDS; i++){ if ((author->friends[i] != NULL) && (author->friends[i]->name == target->name)){ flag = 1; } } if(flag != 1){ //if flag == 1, then they are friends. So we return if != 1. return 1; } Post *newpost = malloc(sizeof(Post)); strcpy(newpost->author, author->name); newpost->contents = contents; time_t creation_time = time(NULL); *(newpost->date ) = creation_time; newpost->next = target->first_post; target->first_post = newpost; return 0; }
I want to allocate memory on the heap for the current time. Then I want to set newpost->date to point to this time.
null
63c647895f004bf4898cf496
2023-02-13T21:29:42.186Z
Help Fix Code
v1
null
for(int i=0; i<MAX_FRIENDS - 1; i++){ if(strcmp(curr->friends[i]->name, name) == 0){ //deleted user is in the list. curr->friends[MAX_FRIENDS - 1] = NULL; //Last element must be NULL after deletion. int j = i; for(int j; j < MAX_FRIENDS-1; j++){ //from i(index with deleted user), shift over every element to the left curr->friends[j] = curr->friends[j + 1]; } } }
I want to iterate through elements up until a point. Then if I reach that point, I want to shift each element from that point onwards to the left.
null
63c647895f004bf4898cf496
2023-02-13T21:30:44.138Z
Explain Code
v1
null
for(int i=0; i<MAX_FRIENDS - 1; i++){ if(strcmp(curr->friends[i]->name, name) == 0){ //deleted user is in the list. curr->friends[MAX_FRIENDS - 1] = NULL; //Last element must be NULL after deletion. int j = i; for(int j; j < MAX_FRIENDS-1; j++){ //from i(index with deleted user), shift over every element to the left curr->friends[j] = curr->friends[j + 1]; } } }
null
null
63c647895f004bf4898cf496
2023-02-13T23:05:13.616Z
Help Fix Code
v1
null
User *current = *user_ptr_del; while(current != NULL){ printf("Now in %s\n", current->name); int i=0; for(i; i<MAX_FRIENDS - 1; i++){ if((current->friends[i] != NULL) && (strcmp(current->friends[i]->name, name) == 0)){ for(int i; i < MAX_FRIENDS-1; i++){ //from i(index with deleted user), shift over every element to the left printf("%s Old value: %s\n", current->name, current->friends[i]->name); current->friends[i] = current->friends[i + 1]; printf("%s New value: %s\n", current->name, current->friends[i]->name); } current->friends[MAX_FRIENDS - 1] = NULL; //Last element must be NULL after deletion. } } current = current->next; }
iterate through all of the User objects. For each user, it checks through the User's list of friends.
null
63c647895f004bf4898cf496
2023-02-15T20:22:09.563Z
Question from Code
v1
how would i free the space that is allocated to post->contents
typedef struct user { char name[MAX_NAME]; char profile_pic[MAX_NAME]; // This is a *filename*, not the file contents. struct post *first_post; struct user *friends[MAX_FRIENDS]; struct user *next; } User; typedef struct post { char author[MAX_NAME]; char *contents; time_t *date; struct post *next; } Post;
null
null
63c6478a5f004bf4898cf4a0
2023-01-30T18:40:51.261Z
General Question
v1
how can I scan multiple lines with scanf
null
null
null
63c6478a5f004bf4898cf4a0
2023-01-30T21:56:15.423Z
General Question
v1
/bin/bash: line 1: [: too many arguments
null
null
null
63c6478a5f004bf4898cf4a0
2023-01-30T22:23:11.436Z
General Question
v1
how to read a multiline string using scan f until the end of the string?
null
null
null
63c6478b5f004bf4898cf4a5
2023-01-17T18:40:22.766Z
General Question
v1
what is a pointer
null
null
null
63c6478b5f004bf4898cf4aa
2023-01-18T05:30:49.651Z
General Question
v1
what is wrong with this test error? phone_loop_checker.py::TestPhoneLoop::test_valid fail 0 / 1 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:475: in _exec raise e from e 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:2004: in _communicate self._check_timeout(endtime, orig_timeout, stdout, stderr) /local/packages/python-3.10/lib/python3.10/subprocess.py:1196: in _check_timeout raise TimeoutExpired( E subprocess.TimeoutExpired: Command '['./phone_loop']' timed out after 2 seconds
null
null
null
63c6478b5f004bf4898cf4aa
2023-01-18T06:06:43.169Z
Help Fix Code
v1
null
int main() { char phone[11]; int i; scanf("%s", phone); do { scanf("%d", &i); if (i == -1) { printf("%s\n", phone); } else if (0 <= i && i <= 9) { printf("%c\n", phone[i]); } else { printf("ERROR"); return 1; } } while (i != 1); return 0; }
Your task is to write a C program called phone_loop.c. This program will again read from standard input using scanf and take no command-line arguments. Similar to phone.c, this program reads a 10-character string as the first input value but then it repeatedly reads integers until standard input is closed. (Hint: Use a while loop that checks the return value of scanf to accomplish this. Check the man page for scanf to determine the return value when the input stream is closed.) After each integer the output produced is as before: if the integer is -1, the full string is printed if the integer is between 0 and 9, the individual character at that position is printed if the integer is less than -1 or greater than 9, the message "ERROR" is printed (to stdout) In each case the printing is followed by a newline character. When the program finishes running, main returns with a 0 return code if there were no errors and with a 1 return code otherwise. Note: the program must not print anything other than then the values specified.
null
63c6478b5f004bf4898cf4aa
2023-01-18T06:17:09.656Z
Help Fix Code
v1
null
int main() { char phone[11]; int i; int result_to_check; scanf("%s", phone); do { result_to_check = scanf("%d", &i); if (i == -1) { printf("%s\n", phone); } else if (0 <= i && i <= 9) { printf("%c\n", phone[i]); } else { printf("ERROR"); return 1; } } while (result_to_check != EOF); return 0; }
Your task is to write a C program called phone_loop.c. This program will again read from standard input using scanf and take no command-line arguments. Similar to phone.c, this program reads a 10-character string as the first input value but then it repeatedly reads integers until standard input is closed. (Hint: Use a while loop that checks the return value of scanf to accomplish this. Check the man page for scanf to determine the return value when the input stream is closed.) After each integer the output produced is as before: if the integer is -1, the full string is printed if the integer is between 0 and 9, the individual character at that position is printed if the integer is less than -1 or greater than 9, the message "ERROR" is printed (to stdout) In each case the printing is followed by a newline character. When the program finishes running, main returns with a 0 return code if there were no errors and with a 1 return code otherwise. Note: the program must not print anything other than then the values specified.
null
63c6478c5f004bf4898cf4af
2023-01-21T05:17:53.406Z
General Question
v1
what does ls -s do
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T05:44:44.838Z
General Question
v1
what does the number next to total in the output of ls -l mean
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T06:21:26.514Z
General Question
v1
what is strtod in c
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T06:39:37.920Z
General Question
v1
why is the first argument of argv indexed at 1
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T06:41:55.803Z
General Question
v1
when creating strings in C, do we need one extra element to hold any special characters?
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T06:49:16.413Z
General Question
v1
how do I take in a string as an argument
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T06:54:55.484Z
General Question
v1
generate a detailed documentation of `fgets` with usage examples and explanations
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T07:38:32.368Z
General Question
v1
how do I store a 5 length string from the command line argument
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T07:41:14.230Z
General Question
v1
does c break conditionals early with &&
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T07:51:36.866Z
General Question
v1
how do I skip a line from the input with scanf
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T08:08:44.352Z
General Question
v1
how do I split a string
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T08:31:11.107Z
General Question
v1
string formatting doucmentation
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T08:41:47.326Z
General Question
v1
is this valid permission[10] = "---------\0";
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T09:03:38.625Z
General Question
v1
print without special characters
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T09:16:28.857Z
General Question
v1
how do you properly compare strings in c
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T09:23:05.125Z
Question from Code
v1
how would I properly point to the parameters
int check_permissions(char *current_perms, char *required_perms){ int i; for (i = 0; i < 9; i++) { if (strcmp(required_perms[i], "-") == 0 && strcmp(current_perms[i], "-") == 0) { return 1; } } return 0; }
null
null
63c6478c5f004bf4898cf4af
2023-01-21T09:27:28.336Z
General Question
v1
how do I compare a string literal with a element of a char array
null
null
null
63c6478c5f004bf4898cf4af
2023-01-21T09:41:02.596Z
Question from Code
v1
what does this format mean
%*[^\n]
null
null
63c6478c5f004bf4898cf4af
2023-01-21T09:41:46.825Z
General Question
v1
can you explain %*[^\n] in detail
null
null
null
63c6478c5f004bf4898cf4af
2023-01-23T02:01:23.510Z
General Question
v1
typecast bool to int in c
null
null
null
63c6478c5f004bf4898cf4af
2023-01-23T02:08:47.091Z
General Question
v1
how do I call helper functions from another file
null
null
null
63c6478c5f004bf4898cf4af
2023-01-23T02:23:15.638Z
General Question
v1
does c automatically convert integers to bools in conditionals
null
null
null
63c6478c5f004bf4898cf4af
2023-01-24T23:40:56.421Z
Question from Code
v1
is this valid
int *build_array(char **strs, int size) { int **array_pointer; array_pointer = malloc(sizeof(int) * size); int i = 0; for (i = 0, i < size;, i++) { strtol((*array_pointer)[i], NULL, 10); } return array_pointer; }
null
null
63c6478c5f004bf4898cf4af
2023-02-01T00:57:35.283Z
General Question
v1
provide documentation for strncmp
null
null
null
63c6478c5f004bf4898cf4af
2023-02-01T01:06:10.206Z
General Question
v1
does argc include the name of the file
null
null
null
63c6478c5f004bf4898cf4af
2023-02-01T01:28:52.955Z
Help Fix Code
v1
null
if (strlen(argv[1]) == strlen(argv[2]) && strncmp(argv[1], argv[2], strlen(argv[1]) == 0)) { printf("Same\n"); }
it should compare if the 2 strings are equal
null
63c6478c5f004bf4898cf4af
2023-02-01T02:10:47.376Z
General Question
v1
difference between string literal and constant
null
null
null
63c6478c5f004bf4898cf4af
2023-02-01T02:13:42.922Z
General Question
v1
does adding a null terminator in the middle of a stack allocated string change the pointer of the stack
null
null
null
63c6478c5f004bf4898cf4af
2023-02-01T02:25:23.315Z
General Question
v1
how do you check if 2 strings are equal
null
null
null
63c6478c5f004bf4898cf4af
2023-02-01T02:27:04.131Z
Explain Code
v1
null
char *a = argv[1]; char *b = argv[2]; if (*a == *b) { printf("Same\n"); }
null
null
63c6478c5f004bf4898cf4af
2023-02-10T19:57:29.226Z
General Question
v1
how do I check for memory leaks
null
null
null
63c6478c5f004bf4898cf4af
2023-02-15T00:32:11.598Z
General Question
v1
provide code for basic linked list traversal pattern
null
null
null
63c6478c5f004bf4898cf4af
2023-02-15T00:42:49.535Z
General Question
v1
c do while
null
null
null
63c6478c5f004bf4898cf4af
2023-02-15T01:02:08.432Z
General Question
v1
how do you vie stderror
null
null
null
63c6478c5f004bf4898cf4af
2023-02-15T01:32:38.840Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { // Check username length if (strlen(name) > MAX_NAME - 1) { return 2; } User * curr = *user_ptr_add; // Check empty list if (curr == NULL) { User *new_user = malloc(sizeof(User)); strncpy(new_user->name, name, MAX_NAME); new_user->name[MAX_NAME-1] = '\0'; * user_ptr_add = new_user; return 0; } do { // Guarantee check first element if (strcmp(curr->name, name) == 0) { return 1; } curr = curr->next; } while (curr != NULL); // Add new User User *new_user = malloc(sizeof(User)); strncpy(new_user->name, name, MAX_NAME); new_user->name[MAX_NAME-1] = '\0'; curr->next = new_user; return 0; }
accepts a string up to length MAX_NAME
null
63c6478c5f004bf4898cf4af
2023-02-15T02:56:28.050Z
General Question
v1
waht does const do in parameter type
null
null
null
63c6478c5f004bf4898cf4af
2023-02-15T05:27:33.566Z
General Question
v1
how to use time()
null
null
null
63c6478c5f004bf4898cf4af
2023-02-15T19:28:47.771Z
General Question
v1
how do you free a struct
null
null
null
63c6478c5f004bf4898cf4af
2023-02-15T19:32:27.011Z
General Question
v1
can I free a pointer but not the object it refers too if I have a copy of the pointer
null
null
null
63c6478c5f004bf4898cf4af
2023-02-15T19:35:51.618Z
General Question
v1
does freeing a char array free the whole array
null
null
null
63c6478c5f004bf4898cf4af
2023-02-21T03:35:27.079Z
General Question
v1
why does fork() not loop infinitely in a program
null
null
null
63c6478c5f004bf4898cf4af
2023-03-15T07:35:49.049Z
Help Write Code
v2
null
null
null
how do you allocate tokens from strtok into an array
63c6478c5f004bf4898cf4af
2023-03-15T16:17:28.903Z
General Question
v2
what is the syntax for a struct pointer
null
null
null
63c6478f5f004bf4898cf4c3
2023-01-18T00:53:11.435Z
Help Fix Code
v1
null
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> int main(){ int a[10]; int size = 10; change(a, size); } static double change(int *a, int size){ int sum; double average; for(int i = 0; i < size; i++){ a[i] = a[i]+10; sum += a[i]; } average = sum / size; return average; }
null
null
63c6478f5f004bf4898cf4c3
2023-01-18T00:54:22.190Z
Help Fix Code
v1
null
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> int main(){ int a[10]; int size = 10; change(a, size); } static double change(int *a, int size){ int sum; double average; for(int i = 0; i < size; i++){ a[i] = a[i]+10; sum += a[i]; } average = sum / size; return average; }
In the space below, write a small program that allocates an array of integers in the main function and passes that array to a function called change. (You’ll also need to pass in the length of the array – why?) The function should do two things: • Add 10 to each element of the array. • Return the average of the new contents of the array.
null
63c6478f5f004bf4898cf4c3
2023-01-18T01:28:32.815Z
General Question
v1
How do I use fgets on an int
null
null
null
63c6478f5f004bf4898cf4c3
2023-01-18T01:38:04.293Z
General Question
v1
Your task is to write a C program called phone_loop.c. This program will again read from standard input using scanf and take no command-line arguments. Similar to phone.c, this program reads a 10-character string as the first input value but then it repeatedly reads integers until standard input is closed. (Hint: Use a while loop that checks the return value of scanf to accomplish this. Check the man page for scanf to determine the return value when the input stream is closed.) After each integer the output produced is as before: if the integer is -1, the full string is printed if the integer is between 0 and 9, the individual character at that position is printed if the integer is less than -1 or greater than 9, the message "ERROR" is printed (to stdout) In each case the printing is followed by a newline character. When the program finishes running, main returns with a 0 return code if there were no errors and with a 1 return code otherwise. Note: the program must not print anything other than then the values specified.
null
null
null
63c6478f5f004bf4898cf4c3
2023-01-18T01:39:23.705Z
Help Write Code
v1
null
null
null
Your task is to write a C program called phone_loop.c. This program will again read from standard input using scanf and take no command-line arguments. Similar to phone.c, this program reads a 10-character string as the first input value but then it repeatedly reads integers until standard input is closed. (Hint: Use a while loop that checks the return value of scanf to accomplish this. Check the man page for scanf to determine the return value when the input stream is closed.) After each integer the output produced is as before: if the integer is -1, the full string is printed if the integer is between 0 and 9, the individual character at that position is printed if the integer is less than -1 or greater than 9, the message "ERROR" is printed (to stdout) In each case the printing is followed by a newline character. When the program finishes running, main returns with a 0 return code if there were no errors and with a 1 return code otherwise. Note: the program must not print anything other than then the values specified.
63c6478f5f004bf4898cf4c3
2023-01-18T02:00:04.785Z
Help Fix Code
v1
null
// Your task is to write a small C program called phone.c that uses scanf to read two values from standard input. #include <stdio.h> int main() { char phone[11]; printf("Type in a phone number:\n"); fgets(phone, 11, stdin); int number; printf("Type in a number:\n"); scanf("%d", &number); if (number == -1){ printf("%s\n", phone); } else if ((0 <= number)&&(number <= 9)){ printf("%d\n", phone[number]); } else { printf("ERROR"); return 1; } return 0; }
Your task is to write a small C program called phone.c that uses scanf to read two values from standard input. The first is a 10 character string and the second is an integer. The program takes no command-line arguments. (You will write this program from scratch, so remember to add, commit, and push.) If the integer is -1, the program prints the full string to stdout. If the integer i is between 0 and 9, the program prints only the corresponding character (i.e., at index i) from the string to stdout. In both of these cases the program returns 0. If the integer is less than -1 or greater than 9, the program prints the message "ERROR" to stdout and returns 1.
null
63c6478f5f004bf4898cf4c3
2023-01-18T02:02:04.096Z
Help Fix Code
v1
null
// Your task is to write a small C program called phone.c that uses scanf to read two values from standard input. #include <stdio.h> int main() { char phone[11]; printf("Type in a phone number:\n"); fgets(phone, 11, stdin); int number; printf("Type in a number:\n"); scanf("%d", &number); if (number == -1){ printf("%s\n", phone); } else if ((0 <= number)&&(number <= 9)){ printf("%d\n", phone[number]); } else { printf("ERROR"); return 1; } return 0; }
It is supposed to print the digit of the phone number corresponding to the variable number
null
63c6478f5f004bf4898cf4c3
2023-01-26T08:20:21.698Z
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; } // TODO: Process command line arguments. char* perms = argv[0]; int sizeLimit = stol(argv[1]) // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. char permissions[10]; int links; char owner[30]; char group[30]; int size; char dateMonth[10]; int dateDay; char dateTime[20]; char file_name[10]; scanf(); int biggerFiles = 0; while (scanf("%s %d %s %s %d %s %d %s %s", permissions, links, owner, group, size, dateMonth, dateDay, dateTime, file_name) == 9) { if (size > sizeLimit) { if (check_permissions(perms, permissions)) { biggerFiles++; } } } printf("%d", biggerFiles); return 0; }
work
null
63c6478f5f004bf4898cf4c3
2023-01-26T08:22:06.102Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *, char *){ }; int 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. char* perms = argv[0]; int sizeLimit = stol(argv[1]) // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. char permissions[10]; int links; char owner[30]; char group[30]; int size; char dateMonth[10]; int dateDay; char dateTime[20]; char file_name[10]; scanf(); int biggerFiles = 0; while (scanf("%s %d %s %s %d %s %d %s %s", permissions, links, owner, group, size, dateMonth, dateDay, dateTime, file_name) == 9) { if (size > sizeLimit) { if (check_permissions(perms, permissions)) { biggerFiles++; } } } printf("%d", biggerFiles); return 0; }
work
null
63c6478f5f004bf4898cf4c3
2023-01-26T08:32:15.548Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *perm1, char *perm2){ for(int i = 0; i < 10; i++){ if (perm1[i] == '-'){ continue; } if (perm1[i] != perm2[i]){ return 0; } } return 1; }; 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. char* perms = argv[0]; int sizeLimit = stol(argv[1]) // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. char permissions[10]; int links; char owner[30]; char group[30]; int size; char dateMonth[10]; int dateDay; char dateTime[20]; char file_name[10]; scanf(); int biggerFiles = 0; while (scanf("%s %d %s %s %d %s %d %s %s", &permissions, &links, &owner, &group, &size, &dateMonth, &dateDay, &dateTime, &file_name) == 9) { if (size > sizeLimit) { if (check_permissions(perms, permissions)) { biggerFiles++; } } } printf("%d", biggerFiles); return 0; }
work
null
63c6478f5f004bf4898cf4c3
2023-01-26T08:37:57.638Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *perm1, char *perm2){ for(int i = 0; i < 10; i++){ if (perm1[i] == '-'){ continue; } if (perm1[i] != perm2[i]){ return 0; } } return 1; }; 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. char *perms = argv[0]; int sizeLimit = atol(argv[1]); // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. char *permissions[10]; int links; char owner[30]; char group[30]; int size; char dateMonth[10]; int dateDay; char dateTime[20]; char file_name[10]; scanf(); int biggerFiles = 0; while (scanf("%s %d %s %s %d %s %d %s %s", *permissions, &links, &owner, &group, &size, &dateMonth, &dateDay, &dateTime, &file_name) == 9) { if (size > sizeLimit) { if (check_permissions(perms, permissions)) { biggerFiles++; } } } printf("%d", biggerFiles); return 0; }
work
null
63c6478f5f004bf4898cf4c3
2023-01-26T08:44:04.822Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *perm1, char *perm2){ for(int i = 0; i < 10; i++){ if (perm1[i] == '-'){ continue; } if (perm1[i] != perm2[i]){ return 0; } } return 1; }; 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. char *perms = argv[0]; int sizeLimit = atol(argv[1]); // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. char permissions[10]; int links; char owner[30]; char group[30]; int size; char dateMonth[10]; int dateDay; char dateTime[20]; char file_name[10]; scanf(); int biggerFiles = 0; while (scanf("%s %d %s %s %d %s %d %s %s", permissions, links, owner, group, size, dateMonth, dateDay, dateTime, file_name) == 9) { if (size > sizeLimit) { if (check_permissions(perms, permissions)) { biggerFiles++; } } } printf("%d", biggerFiles); return 0; }
work
null
63c6478f5f004bf4898cf4c3
2023-01-26T09:00:10.833Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *perm1, char *perm2){ for(int i = 0; i < 10; i++){ if (perm1[i] == '-'){ continue; } if (perm1[i] != perm2[i]){ return 0; } } return 1; }; 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. char perms[10]; int sizeLimit = atol(argv[1]); // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. if (argc == 2) { *perms = "---------"; } else { for (int i = 0; i < 9; i++) { perms[i] = argv[2][i]; } } char permissions[10]; int links; char owner[30]; char group[30]; int size; char dateMonth[10]; int dateDay; char dateTime[20]; char file_name[10]; scanf("%s %d"); int biggerFiles = 0; while (scanf("%s %*d %s %s %*d %s %*d %s %s", permissions, links, owner, group, size, dateMonth, dateDay, dateTime, file_name) == 9) { if (size > sizeLimit) { if (check_permissions(perms, permissions)) { biggerFiles++; } } } printf("%d", biggerFiles); return 0; }
work
null
63c6478f5f004bf4898cf4c3
2023-01-26T09:24:56.902Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(char *perm1, char *perm2){ for(int i = 0; i < 10; i++){ if (perm2[i] == '-'){ continue; } if (perm1[i] != perm2[i]){ return 0; } } return 1; }; 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. char *perms = "----------"; int sizeLimit = atol(argv[1]); // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. if (argc == 3) { for (int i = 0; i < 10; i++) { perms[i] = argv[2][i]; } } char *permissions = malloc(10 * sizeof(char)); int size; scanf("%*s %*d"); int biggerFiles = 0; while (scanf("%s %*d %*s %*s %d %*s %*d %*s %*s", permissions, &size) == 2) { if (size > sizeLimit) { if (check_permissions(permissions, perms)) { biggerFiles++; } } } printf("%d \n", biggerFiles); return 0; }
work
null
63c6478f5f004bf4898cf4c3
2023-01-26T17:46:54.384Z
General Question
v1
How do I use functions defined in another file?
null
null
null
63c6478f5f004bf4898cf4c3
2023-02-01T00:24:21.321Z
General Question
v1
When do I use -> vs .
null
null
null
63c6478f5f004bf4898cf4c3
2023-02-01T00:25:35.178Z
General Question
v1
When do I use -> vs . ? Provide examples
null
null
null
63c6478f5f004bf4898cf4c3
2023-02-08T01:27:13.157Z
Help Write Code
v1
null
null
null
Read in pixel array by following these instructions: * * 1. First, allocate space for m `struct pixel *` values, where m is the * height of the image. Each pointer will eventually point to one row of * pixel data. * 2. For each pointer you just allocated, initialize it to point to * heap-allocated space for an entire row of pixel data. * 3. Use the given file and pixel_array_offset to initialize the actual * struct pixel values. Assume that `sizeof(struct pixel) == 3`, which is * consistent with the bitmap file format. * NOTE: We've tested this assumption on the Teaching Lab machines, but * if you're trying to work on your own computer, we strongly recommend * checking this assumption! * 4. Return the address of the first `struct pixel *` you initialized.
63c6478f5f004bf4898cf4c3
2023-02-08T01:29:21.598Z
Help Write Code
v1
null
null
null
Read in pixel array by following these instructions: 1. First, allocate space for m `struct pixel *` values, where m is the height of the image. Each pointer will eventually point to one row of pixel data. 2. For each pointer you just allocated, initialize it to point to heap-allocated space for an entire row of pixel data. 3. Use the given file and pixel_array_offset to initialize the actual struct pixel values. Assume that `sizeof(struct pixel) == 3`, which is consistent with the bitmap file format. 4. Return the address of the first `struct pixel *` you initialized.
63c6478f5f004bf4898cf4c3
2023-02-25T22:04:09.792Z
General Question
v1
What are default values for variables in C
null
null
null
63c6478f5f004bf4898cf4c3
2023-02-25T22:08:02.997Z
General Question
v1
Does a program terminate when main returns? Justify your answer.
null
null
null
63c6478f5f004bf4898cf4c3
2023-02-27T22:50:22.460Z
Question from Code
v1
Does this work
int** code = {{0, 1}, {1, 2}}; int num = code[0][0]; int*** codeptr = &&num;
null
null
63c6478f5f004bf4898cf4c3
2023-02-27T22:50:50.246Z
Question from Code
v1
Why doesn't this work
int** code = {{0, 1}, {1, 2}}; int num = code[0][0]; int*** codeptr = &&num;
null
null
63c6478f5f004bf4898cf4c3
2023-02-27T22:51:38.260Z
Question from Code
v1
Why is line 3 invalid? Explain using 3-5 sentences.
int** code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int*** codeptr = &&num;
null
null
63c6478f5f004bf4898cf4c3
2023-02-27T22:52:11.838Z
Question from Code
v1
Does this work? Explain in 3-5 sentences.
int** code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int** codeptr = &&num;
null
null
63c6478f5f004bf4898cf4c3
2023-02-27T22:52:49.150Z
Question from Code
v1
Does this work?
int code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int** codeptr = &&num;
null
null
63c6478f5f004bf4898cf4c3
2023-02-27T22:53:36.183Z
Question from Code
v1
Explain why this code does not work in 3-5 sentences.
int code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int** codeptr = &&num;
null
null
63c6478f5f004bf4898cf4c3
2023-02-27T22:54:04.553Z
Question from Code
v1
Does this work?
int code[2][2] = {{0, 1}, {1, 2}}; int num = code[0][0]; int** codeptr = &&&num;
null
null
63c6478f5f004bf4898cf4c3
2023-02-27T22:54:29.353Z
General Question
v1
Can I ever have 2 or more & in a row?
null
null
null
63c6478f5f004bf4898cf4c3
2023-03-08T02:14:16.379Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #define MAXLINE 256 #define SUCCESS "Password verified\n" #define INVALID "Invalid password\n" #define NO_USER "No such user\n" /* Your task is to complete checkpasswd.c, which reads a user id and password from stdin, creates a new process to run the validate program, sends it the user id and password, and prints a message to stdout reporting whether the validation is successful. Your program should use the exit status of the validate program to determine which of the three following messages to print: "Password verified" if the user id and password match. "Invalid password" if the user id exists, but the password does not match. "No such user" if the user id is not recognized The exact messages are given in the starter code as defined constants. The only case that should be handled directly in checkpasswd is the case where either the userid or password are too long. This is to prevent sending the wrong number of bytes to validate. Note that in the given password file pass.txt, the "killerwhales:swim" has a user id that is too large, and "monkeys:eatcoconuts" has a password that is too long. The examples are expected to fail, but the other cases should work correctly. You will find the following system calls useful: fork, exec, pipe, dup2, write, wait (along with WIFEXITED, WEXITSTATUS). You may not use popen or pclose in your solution. Important: execl arguments Week 7 Video 6 "Running Different Programs" demonstrates a version of execl that takes only two arguments. The signature for execl is: int execl(const char *path, const char *arg0, ... *, (char *)NULL ); In the video, the execl call only passed two arguments (execl("./hello", NULL)), but that shortcut doesn't work on teach.cs. Instead, you need to pass the middle argument (respresenting argv[0]) explicitly: execl(".hello", "hello", NULL). Let's consider two more examples. If you want to call the executable ./giant with the arguments fee fi fo, you would do it like this: execl(".giant", "giant", "fee", "fi", "fo", NULL); If you want to call ./giant with no arguments you would call it like this: execl(".giant", "giant", NULL); */ int main(void) { char user_id[MAXLINE]; char password[MAXLINE]; /* The user will type in a user name on one line followed by a password on the next. DO NOT add any prompts. The only output of this program will be one of the messages defined above. Please read the comments in validate carefully */ if (fgets(user_id, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (fgets(password, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (strlen(user_id) > MAXLINE || strlen(password) > MAXLINE) { exit(1); } int fd[2]; pipe(fd); pid_t pid = fork(); if (pid < 0) { perror("fork"); exit(1); } else if (pid == 0) { dup2(fd[1], STDOUT_FILENO); close(fd[0]); close(fd[1]); execl("./validate", "validate", user_id, password, NULL); perror("execl"); exit(1); } else { int status; wait(&status); int exit_status = WEXITSTATUS(status); switch (exit_status) { case 0: printf(SUCCESS); break; case 1: printf(INVALID); break; case 2: printf(INVALID); break; case 3: printf(NO_USER); break; default: fprintf(stderr, "Unknown exit status: %d\n", exit_status); exit(1); } } return 0; }
Your task is to complete checkpasswd.c, which reads a user id and password from stdin, creates a new process to run the validate program, sends it the user id and password, and prints a message to stdout reporting whether the validation is successful. Your program should use the exit status of the validate program to determine which of the three following messages to print: "Password verified" if the user id and password match. "Invalid password" if the user id exists, but the password does not match. "No such user" if the user id is not recognized The exact messages are given in the starter code as defined constants. The only case that should be handled directly in checkpasswd is the case where either the userid or password are too long. This is to prevent sending the wrong number of bytes to validate. Note that in the given password file pass.txt, the "killerwhales:swim" has a user id that is too large, and "monkeys:eatcoconuts" has a password that is too long. The examples are expected to fail, but the other cases should work correctly. You will find the following system calls useful: fork, exec, pipe, dup2, write, wait (along with WIFEXITED, WEXITSTATUS). You may not use popen or pclose in your solution. Important: execl arguments Week 7 Video 6 "Running Different Programs" demonstrates a version of execl that takes only two arguments. The signature for execl is: int execl(const char *path, const char *arg0, ... *, (char *)NULL ); In the video, the execl call only passed two arguments (execl("./hello", NULL)), but that shortcut doesn't work on teach.cs. Instead, you need to pass the middle argument (respresenting argv[0]) explicitly: execl(".hello", "hello", NULL). Let's consider two more examples. If you want to call the executable ./giant with the arguments fee fi fo, you would do it like this: execl(".giant", "giant", "fee", "fi", "fo", NULL); If you want to call ./giant with no arguments you would call it like this: execl(".giant", "giant", NULL); */ int main(void) { char user_id[MAXLINE]; char password[MAXLINE]; /* The user will type in a user name on one line followed by a password on the next. DO NOT add any prompts. The only output of this program will be one of the messages defined above. Please read the comments in validate carefully
null
63c6478f5f004bf4898cf4c3
2023-03-08T02:15:09.790Z
Question from Code
v1
why doesn't this work?
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #define MAXLINE 256 #define SUCCESS "Password verified\n" #define INVALID "Invalid password\n" #define NO_USER "No such user\n" /* Your task is to complete checkpasswd.c, which reads a user id and password from stdin, creates a new process to run the validate program, sends it the user id and password, and prints a message to stdout reporting whether the validation is successful. Your program should use the exit status of the validate program to determine which of the three following messages to print: "Password verified" if the user id and password match. "Invalid password" if the user id exists, but the password does not match. "No such user" if the user id is not recognized The exact messages are given in the starter code as defined constants. The only case that should be handled directly in checkpasswd is the case where either the userid or password are too long. This is to prevent sending the wrong number of bytes to validate. Note that in the given password file pass.txt, the "killerwhales:swim" has a user id that is too large, and "monkeys:eatcoconuts" has a password that is too long. The examples are expected to fail, but the other cases should work correctly. You will find the following system calls useful: fork, exec, pipe, dup2, write, wait (along with WIFEXITED, WEXITSTATUS). You may not use popen or pclose in your solution. Important: execl arguments Week 7 Video 6 "Running Different Programs" demonstrates a version of execl that takes only two arguments. The signature for execl is: int execl(const char *path, const char *arg0, ... *, (char *)NULL ); In the video, the execl call only passed two arguments (execl("./hello", NULL)), but that shortcut doesn't work on teach.cs. Instead, you need to pass the middle argument (respresenting argv[0]) explicitly: execl(".hello", "hello", NULL). Let's consider two more examples. If you want to call the executable ./giant with the arguments fee fi fo, you would do it like this: execl(".giant", "giant", "fee", "fi", "fo", NULL); If you want to call ./giant with no arguments you would call it like this: execl(".giant", "giant", NULL); */ int main(void) { char user_id[MAXLINE]; char password[MAXLINE]; /* The user will type in a user name on one line followed by a password on the next. DO NOT add any prompts. The only output of this program will be one of the messages defined above. Please read the comments in validate carefully */ if (fgets(user_id, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (fgets(password, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (strlen(user_id) > MAXLINE || strlen(password) > MAXLINE) { exit(1); } int fd[2]; pipe(fd); pid_t pid = fork(); if (pid < 0) { perror("fork"); exit(1); } else if (pid == 0) { dup2(fd[1], STDOUT_FILENO); close(fd[0]); close(fd[1]); execl("./validate", "validate", user_id, password, NULL); perror("execl"); exit(1); } else { int status; wait(&status); int exit_status = WEXITSTATUS(status); switch (exit_status) { case 0: printf(SUCCESS); break; case 1: printf(INVALID); break; case 2: printf(INVALID); break; case 3: printf(NO_USER); break; default: fprintf(stderr, "Unknown exit status: %d\n", exit_status); exit(1); } } return 0; }
null
null
63c6478f5f004bf4898cf4c3
2023-03-15T04:53:28.948Z
Help Fix Code
v2
work
#include<stdio.h>#include<stdlib.h>#include<string.h>#include"pmake.h"Rule*parse_file(FILE*fp){Rule*rules=makeRule();Rule*cur=rules;Action*cur_act=makeAction();Dependency*cur_dep=makeDependency();char*line=malloc(sizeof(char*)*MAXLINE);while(fgets(line,sizeof(MAXLINE),fp)){if(is_comment_or_empty(line)){continue;}char**args=parseLine(line);if(line[0]=='\t'){Action*cur_act=cur->actions;while(cur_act->next_act!=NULL){cur_act=cur_act->next_act;}cur_act->next_act=malloc(sizeof(Action));cur_act->next_act=makeAction();cur_act->next_act->args=args;}else{Rule*cur=rules;while(cur->next_rule!=NULL){cur=cur->next_rule;}for(inti=0;i<sizeof(args);i++){Rule*searchRule=rules;cur_dep=cur->dependencies;while(searchRule->next_rule!=NULL){if(strcmp(searchRule->target,args[i])==0){if(i==0){cur=searchRule;break;}elseif(i>=2){while(cur_dep->next_dep!=NULL){cur_dep=cur_dep->next_dep;}cur_dep->rule=searchRule;cur_dep->next_dep=makeDependency();cur_dep=cur_dep->next_dep;break;}}searchRule=searchRule->next_rule;}if(searchRule->next_rule==NULL){if(i==0){Rule*oldcur=cur;cur->target=args[0];cur->dependencies=makeDependency();cur_dep=cur->dependencies;cur->actions=makeAction();for(intj=2;j<sizeof(args);j++){cur_dep->rule=makeRule();cur_dep->rule->target=args[j];cur_dep->next_dep=makeDependency();cur_dep=cur_dep->next_dep;cur->next_rule=cur_dep->rule;cur=cur->next_rule;}cur->next_rule=makeRule();cur=oldcur;break;}elseif(i>=2){Rule*newcur=rules;while(newcur->next_rule!=NULL){newcur=newcur->next_rule;}Rule*new_rule=makeRule();new_rule->target=args[i];newcur->next_rule=new_rule;cur_dep->rule=new_rule;cur_dep->next_dep=makeDependency();cur_dep=cur_dep->next_dep;break;}}}}}returnrules;}
null
null
63c6478f5f004bf4898cf4c3
2023-03-15T04:56:43.280Z
Help Fix Code
v2
work
Rule *parse_file(FILE *fp) { Rule *rules = makeRule(); Rule *cur = rules; Action *cur_act = makeAction(); Dependency *cur_dep = makeDependency(); char *line = malloc(sizeof(char*) * MAXLINE); while (fgets(line, sizeof(MAXLINE), fp)) { if (is_comment_or_empty(line)) { continue; } char** args = parseLine(line); if (line[0] == '\t') { Action *cur_act = cur->actions; while (cur_act->next_act != NULL) { cur_act = cur_act->next_act; } cur_act->next_act = malloc(sizeof(Action)); cur_act->next_act = makeAction(); cur_act->next_act->args = args; } else { Rule *cur = rules; while (cur->next_rule != NULL) { cur = cur->next_rule; } for (int i = 0; i < sizeof(args); i++) { Rule *searchRule = rules; cur_dep = cur->dependencies; while (searchRule->next_rule != NULL) { if (strcmp(searchRule->target, args[i]) == 0) { if (i == 0){ cur = searchRule; break; } else if (i >= 2) { while (cur_dep->next_dep != NULL) { cur_dep = cur_dep->next_dep; } cur_dep->rule = searchRule; cur_dep->next_dep = makeDependency(); cur_dep = cur_dep->next_dep; break; } } searchRule = searchRule->next_rule; } if (searchRule->next_rule == NULL) { if (i == 0){ Rule *oldcur = cur; cur->target = args[0]; cur->dependencies = makeDependency(); cur_dep = cur->dependencies; cur->actions = makeAction(); for (int j = 2; j < sizeof(args); j++) { cur_dep->rule = makeRule(); cur_dep->rule->target = args[j]; cur_dep->next_dep = makeDependency(); cur_dep = cur_dep->next_dep; cur->next_rule = cur_dep->rule; cur = cur->next_rule; } cur->next_rule = makeRule(); cur = oldcur; break; } else if (i >= 2) { Rule *newcur = rules; while (newcur->next_rule != NULL) { newcur = newcur->next_rule; } Rule *new_rule = makeRule(); new_rule->target = args[i]; newcur->next_rule = new_rule; cur_dep->rule = new_rule; cur_dep->next_dep = makeDependency(); cur_dep = cur_dep->next_dep; break; } } } } } return rules; }
null
null
63c6478f5f004bf4898cf4c3
2023-03-15T04:58:16.755Z
Explain Code
v2
null
Rule *parse_file(FILE *fp) { Rule *rules = makeRule(); Rule *cur = rules; Action *cur_act = makeAction(); Dependency *cur_dep = makeDependency(); char *line = malloc(sizeof(char *) * MAXLINE); while (fgets(line, sizeof(MAXLINE), fp)) { if (is_comment_or_empty(line)) { continue; } char **args = parseLine(line); if (line[0] == '\t') { Action *cur_act = cur->actions; while (cur_act->next_act != NULL) { cur_act = cur_act->next_act; } cur_act->next_act = malloc(sizeof(Action)); cur_act->next_act = makeAction(); cur_act->next_act->args = args; } else { Rule *cur = rules; while (cur->next_rule != NULL) { cur = cur->next_rule; } for (int i = 0; i < sizeof(args); i++) { Rule *searchRule = rules; cur_dep = cur->dependencies; while (searchRule->next_rule != NULL) { if (strcmp(searchRule->target, args[i]) == 0) { if (i == 0) { cur = searchRule; break; } else if (i >= 2) { while (cur_dep->next_dep != NULL) { cur_dep = cur_dep->next_dep; } cur_dep->rule = searchRule; cur_dep->next_dep = makeDependency(); cur_dep = cur_dep->next_dep; break; } } searchRule = searchRule->next_rule; } if (searchRule->next_rule == NULL) { if (i == 0) { Rule *oldcur = cur; cur->target = args[0]; cur->dependencies = makeDependency(); cur_dep = cur->dependencies; cur->actions = makeAction(); for (int j = 2; j < sizeof(args); j++) { cur_dep->rule = makeRule(); cur_dep->rule->target = args[j]; cur_dep->next_dep = makeDependency(); cur_dep = cur_dep->next_dep; cur->next_rule = cur_dep->rule; cur = cur->next_rule; } cur->next_rule = makeRule(); cur = oldcur; break; } else if (i >= 2) { Rule *newcur = rules; while (newcur->next_rule != NULL) { newcur = newcur->next_rule; } Rule *new_rule = makeRule(); new_rule->target = args[i]; newcur->next_rule = new_rule; cur_dep->rule = new_rule; cur_dep->next_dep = makeDependency(); cur_dep = cur_dep->next_dep; break; } } } } } return rules; }
null
null
63c6478f5f004bf4898cf4c3
2023-03-15T05:04:03.404Z
Help Fix Code
v2
char** parseLine(char* line) { // Parse the line char** args = malloc(sizeof(char**)); char* arg = strtok(line, " "); // Parse the arguments and add them to args while (arg != NULL) { args = realloc(args, sizeof(char**) * (sizeof(args) + 1)); args[sizeof(args)] = arg; arg = strtok(NULL, " "); } return args; }
null
null
63c6478f5f004bf4898cf4c3
2023-03-15T05:05:22.246Z
Help Fix Code
v2
This should read the characters from line and generate an array of strings, one per argument
char** parseLine(char* line) { // Parse the line char** args = malloc(sizeof(char**)); char* arg = strtok(line, " "); // Parse the arguments and add them to args while (arg != NULL) { args = realloc(args, sizeof(char**) * (sizeof(args) + 1)); args[sizeof(args)] = arg; arg = strtok(NULL, " "); } return args; }
null
null
63c6478f5f004bf4898cf4c3
2023-03-15T05:10:07.536Z
Help Fix Code
v2
Split the strings in line into an array using spaces and return a list of strings
char** parseLine(char* line) { // Parse the line char** args = malloc(sizeof(char*)); char* arg = strtok(line, " "); // Parse the arguments and add them to args int i = 0; while (arg != NULL) { args[i] = malloc(strlen(arg) + 1); strcpy(args[i], arg); i++; args = realloc(args, sizeof(char*) * (i + 1)); arg = strtok(NULL, " "); } args[i] = NULL; return args; }
null
null
63c6478f5f004bf4898cf4c3
2023-03-15T06:25:48.812Z
Help Fix Code
v2
Does this work?
cur_dep->rule = makeRule(); cur->next_rule = cur_dep->rule; cur = cur->next_rule;
null
null
63c6478f5f004bf4898cf4c3
2023-04-05T05:44:17.297Z
Help Fix Code
v2
compile
char* list_users(const User *curr) { const User *og_user = curr; char *user_list = NULL; int size = 11; while (curr != NULL) { size += strlen(curr->name) + 3; curr = curr->next; } user_list = malloc(sizeof(char)*size); if (user_list == NULL) { perror("malloc"); exit(1); } else { strcat(user_list, "User List\r\n"); curr = og_user; while (curr != NULL) { strcat(user_list, "\t"); strcat(user_list, curr->name); strcat(user_list, "\r\n"); curr = curr->next; } } return user_list; }
null
null
63c6478f5f004bf4898cf4c3
2023-04-25T20:20:54.854Z
General Question
v2
how do i do stuff for sockets
null
null
null
63c647905f004bf4898cf4cd
2023-02-08T02:13:13.970Z
General Question
v1
When I call gcc on a c file in the terminal, what file type is the output?
null
null
null
63c647945f004bf4898cf4e6
2023-01-17T18:13:54.207Z
General Question
v1
what is a pointer variable?
null
null
null