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
63c647ea5f004bf4898cf7c5
2023-02-14T07:14:25.851Z
Question from Code
v1
Are there any issues
while (curr != NULL){ if (curr != user->first_post){ printf("\n"); printf("===\n"); printf("\n"); } printf("From: %s\n", curr->author); printf("Date: %s\n", ctime(curr->date)); printf("%s\n", curr->contents); curr = curr->next; } printf("------------------------------------------\n");
null
null
63c647ea5f004bf4898cf7c5
2023-02-14T22:58:42.720Z
Explain Code
v1
null
// Go through all the user's posts and free memory allocated for it Post *posts = NULL; Post *prev_post = to_delete->first_post; while (prev_post != NULL){ posts = prev_post; free(posts->contents); free(posts->date); prev_post = prev_post->next; free(posts); } // Free user itself's memory free(to_delete); return 0;
null
null
63c647ea5f004bf4898cf7c5
2023-02-14T22:59:37.987Z
Help Fix Code
v1
null
// Go through all the user's posts and free memory allocated for it Post *posts = NULL; Post *prev_post = to_delete->first_post; while (prev_post != NULL){ posts = prev_post; free(posts->contents); free(posts->date); prev_post = prev_post->next; free(posts); } // Free user itself's memory free(to_delete); return 0;
I have a never terminating loop here
null
63c647ea5f004bf4898cf7c5
2023-02-17T19:36:59.903Z
Help Fix Code
v1
null
// Allocate Null space to all the characters in dest memset(dest, '\0', capacity); // Go through the src string and copy characters int i = 0; for (i; i < (capacity-1); i++){ if (src[i] != '\0'){ dest[i] = src[i]; } } return dest;
It is supposed to act like strncopy
null
63c647ea5f004bf4898cf7c5
2023-04-06T09:08:24.923Z
Help Fix Code
v2
The code is not outputting Welcome.\r\n even though its a new user
// New user if (found == 0){ // Welcome the client char *message = "Welcome.\r\n"; write(new_user->fd, message, strlen(message)); // Note down the name strncpy(new_user->name, buf, strlen(new_user->name)); new_user->name[31] = '\0'; } }
null
null
63c647ec5f004bf4898cf7d4
2023-01-28T05:08:17.395Z
General Question
v1
how do i ignore a line of input using scanf
null
null
null
63c647ec5f004bf4898cf7d4
2023-02-09T22:31:37.938Z
Question from Code
v1
what is the complexity of this code
AVL_Node* search(AVL_Node* node, int key) { //*** if (node == NULL) { return NULL; } if (key == node->key) { return node; } if (key < node->key) { return search(node->left, key); } return search(node->right, key); }
null
null
63c647ec5f004bf4898cf7d4
2023-02-09T22:32:10.783Z
General Question
v1
pseudocode for avl insert?
null
null
null
63c647ec5f004bf4898cf7d4
2023-03-10T19:34:41.001Z
General Question
v2
what are processes in C
null
null
null
63c647ec5f004bf4898cf7d4
2023-03-10T21:44:20.724Z
General Question
v2
what does dup2 do
null
null
null
63c647ec5f004bf4898cf7d4
2023-03-10T21:44:51.210Z
General Question
v2
what is a file descriptor
null
null
null
63c647ec5f004bf4898cf7d4
2023-03-10T22:02:32.926Z
Question from Code
v2
explain what this program does
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #define MAXLINE 256 #define MAX_PASSWORD 8 #define SUCCESS "Password verified\n" #define INVALID "Invalid password\n" #define NO_USER "No such user\n" int main(void) { char user_id[MAXLINE]; char password[MAXLINE]; if (fgets(user_id, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (fgets(password, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } int fd[2]; if (pipe(fd) == -1) { perror("pipe"); exit(1); } pid_t pid = fork(); if (pid == -1) { perror("fork"); exit(1); } if (pid == 0) { close(fd[0]); dup2(fd[1], STDOUT_FILENO); close(fd[1]); execlp("./validate", "./validate", NULL); perror("execlp"); exit(1); } else { close(fd[1]); dup2(fd[0], STDIN_FILENO); close(fd[0]); wait(NULL); char buf[MAXLINE]; if (fgets(buf, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (strcmp(buf, SUCCESS) == 0) { printf("Password verified"); } else if (strcmp(buf, INVALID) == 0) { printf("Invalid password"); } else if (strcmp(buf, NO_USER) == 0) { printf("No such user"); } else { printf("Unknown error"); } } return 0; }
null
null
63c647ec5f004bf4898cf7d4
2023-03-10T22:04:32.087Z
Question from Code
v2
explain the purpose of the buf variable
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #define MAXLINE 256 #define MAX_PASSWORD 8 #define SUCCESS "Password verified\n" #define INVALID "Invalid password\n" #define NO_USER "No such user\n" int main(void) { char user_id[MAXLINE]; char password[MAXLINE]; if (fgets(user_id, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (fgets(password, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } int fd[2]; if (pipe(fd) == -1) { perror("pipe"); exit(1); } pid_t pid = fork(); if (pid == -1) { perror("fork"); exit(1); } if (pid == 0) { close(fd[0]); dup2(fd[1], STDOUT_FILENO); close(fd[1]); execlp("./validate", "./validate", NULL); perror("execlp"); exit(1); } else { close(fd[1]); dup2(fd[0], STDIN_FILENO); close(fd[0]); wait(NULL); char buf[MAXLINE]; if (fgets(buf, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (strcmp(buf, SUCCESS) == 0) { printf("Password verified"); } else if (strcmp(buf, INVALID) == 0) { printf("Invalid password"); } else if (strcmp(buf, NO_USER) == 0) { printf("No such user"); } else { printf("Unknown error"); } } return 0; }
null
null
63c647ec5f004bf4898cf7d4
2023-03-10T22:21:13.267Z
Question from Code
v2
what's the purpose of dup2 in this code
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #define MAXLINE 256 #define MAX_PASSWORD 8 #define SUCCESS "Password verified\n" #define INVALID "Invalid password\n" #define NO_USER "No such user\n" int main(void) { char user_id[MAXLINE]; char password[MAXLINE]; if (fgets(user_id, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (fgets(password, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } int fd[2]; if (pipe(fd) == -1) { perror("pipe"); exit(1); } pid_t pid = fork(); if (pid == -1) { perror("fork"); exit(1); } if (pid == 0) { close(fd[0]); dup2(fd[1], STDOUT_FILENO); close(fd[1]); execlp("./validate", "./validate", NULL); perror("execlp"); exit(1); } else { close(fd[1]); dup2(fd[0], STDIN_FILENO); close(fd[0]); wait(NULL); char buf[MAXLINE]; if (fgets(buf, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (strcmp(buf, SUCCESS) == 0) { printf("Password verified"); } else if (strcmp(buf, INVALID) == 0) { printf("Invalid password"); } else if (strcmp(buf, NO_USER) == 0) { printf("No such user"); } else { printf("Unknown error"); } } return 0; }
null
null
63c647ec5f004bf4898cf7d4
2023-03-10T22:42:51.303Z
Question from Code
v2
why does this give invalid file descriptor error when run
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #define MAXLINE 256 #define MAX_PASSWORD 10 #define SUCCESS "Password verified\n" #define INVALID "Invalid password\n" #define NO_USER "No such user\n" int main(void) { char user_id[MAXLINE]; char password[MAXLINE]; if (fgets(user_id, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } if (fgets(password, MAXLINE, stdin) == NULL) { perror("fgets"); exit(1); } int fd[2]; if (pipe(fd) == -1) { perror("pipe"); exit(1); } pid_t pid = fork(); if (pid == -1) { perror("fork"); exit(1); } if (pid == 0) { close(fd[0]); dup2(fd[1], STDOUT_FILENO); close(fd[1]); execlp("./validate", "./validate", NULL); perror("execlp"); exit(1); } else { close(fd[1]); close(fd[0]); int status; wait(&status); close(fd[0]); if (WIFEXITED(status)) { int exit_status = WEXITSTATUS(status); if (exit_status == 0) { printf("%s", SUCCESS); } else if (exit_status == 1) { printf("%s", INVALID); } else if (exit_status == 2) { printf("%s", NO_USER); } else { printf("Unknown error\n"); } } else { printf("Unknown error\n"); } } return 0; }
null
null
63c647ec5f004bf4898cf7d4
2023-03-13T23:49:21.842Z
Help Fix Code
v2
lldb is telling me line 3 is causing a segfault. how do i fix this
target = malloc(sizeof(char) * (strchr(makefile_line, ':') - makefile_line)); strncpy(target, makefile_line, strchr(makefile_line, ':') - makefile_line - 1); target[strchr(makefile_line, ':') - makefile_line - 1] = '\0';
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T02:48:39.895Z
Question from Code
v2
what algorithm is this
Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeEdges, min->fromVertex, min->toVertex, min->weight); } AdjList *adj = graph->adjLists[min->toVertex]; for (int i = 0; i < adj->numNeighbors; i++) { if (!records->finished[adj->neighbors[i].vertex]) { int weight = adj->neighbors[i].weight; if (weight < records->heap->array[adj->neighbors[i].vertex]->weight) { decreasePriority(records->heap, adj->neighbors[i].vertex, weight); records->predecessors[adj->neighbors[i].vertex] = min->toVertex; } } } } return records->tree;
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T02:56:17.134Z
General Question
v2
how do you implement dijkstra's algorithm
null
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T02:59:48.550Z
Question from Code
v2
what algorithm is this
Records *records = initRecords(graph, startVertex); for (int i = 0; i < graph->numVertices; i++) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeEdges, min->fromVertex, min->toVertex, min->weight); } AdjList *adj = graph->adjLists[min->toVertex]; for (int i = 0; i < adj->numNeighbors; i++) { if (!records->finished[adj->neighbors[i].vertex]) { int weight = adj->neighbors[i].weight + min->weight; if (weight < records->heap->array[adj->neighbors[i].vertex]->weight) { decreasePriority(records->heap, adj->neighbors[i].vertex, weight); records->predecessors[adj->neighbors[i].vertex] = min->toVertex; } } } }
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T03:25:06.269Z
Question from Code
v2
consider these two functions
Records *initRecords(Graph *graph, int startVertex) { Records *records = malloc(sizeof(Records)); records->numVertices = graph->numVertices; records->heap = initHeap(graph, startVertex); records->finished = malloc(sizeof(bool) * graph->numVertices); records->predecessors = malloc(sizeof(int) * graph->numVertices); records->tree = malloc(sizeof(Edge) * (graph->numVertices - 1)); records->numTreeEdges = 0; for (int i = 0; i < graph->numVertices; i++) { records->finished[i] = false; records->predecessors[i] = NOTHING; } return records; } MinHeap *initHeap(Graph *graph, int startVertex) { MinHeap *heap = newMinHeap(graph->numVertices); for (int i = 0; i < graph->numVertices; i++) { if (i == startVertex) { insert(heap, newEdge(startVertex, startVertex, 0)); } else { insert(heap, newEdge(startVertex, i, INT_MAX)); } } return heap; }
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T03:40:20.502Z
Question from Code
v2
what is getPaths returning here
Edge *getShortestPaths(Graph *graph, int startVertex) { Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeEdges, min->fromVertex, min->toVertex, min->weight); } AdjList *adj = graph->adjLists[min->toVertex]; for (int i = 0; i < adj->numNeighbors; i++) { if (!records->finished[adj->neighbors[i].vertex]) { int weight = adj->neighbors[i].weight + min->weight; if (weight < records->heap->array[adj->neighbors[i].vertex]->weight) { decreasePriority(records->heap, adj->neighbors[i].vertex, weight); records->heap->array[adj->neighbors[i].vertex]->weight = weight; records->predecessors[adj->neighbors[i].vertex] = min->toVertex; } } } } } AdjList *getPaths(Edge *distTree, int startVertex, int endVertex) { Edge *path = getShortestPaths(distTree, startVertex); return makePath(path, endVertex, startVertex); }
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T03:41:22.909Z
Question from Code
v2
what algorithm(s) are being displayed here
Edge *getShortestPaths(Graph *graph, int startVertex) { Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeEdges, min->fromVertex, min->toVertex, min->weight); } AdjList *adj = graph->adjLists[min->toVertex]; for (int i = 0; i < adj->numNeighbors; i++) { if (!records->finished[adj->neighbors[i].vertex]) { int weight = adj->neighbors[i].weight + min->weight; if (weight < records->heap->array[adj->neighbors[i].vertex]->weight) { decreasePriority(records->heap, adj->neighbors[i].vertex, weight); records->heap->array[adj->neighbors[i].vertex]->weight = weight; records->predecessors[adj->neighbors[i].vertex] = min->toVertex; } } } } return records->tree; } AdjList *getPaths(Edge *distTree, int startVertex, int endVertex) { Edge *path = getShortestPaths(distTree, startVertex); return makePath(path, endVertex, startVertex); }
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T03:59:05.137Z
Explain Code
v2
null
Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Edge *min = extractMin(records->heap); records->finished[min->toVertex] = true; if (min->fromVertex != min->toVertex) { addTreeEdge(records, records->numTreeEdges, min->fromVertex, min->toVertex, min->weight); } AdjList *adj = graph->adjLists[min->toVertex]; for (int i = 0; i < adj->numNeighbors; i++) { if (!records->finished[adj->neighbors[i].vertex]) { int weight = adj->neighbors[i].weight + min->weight; if (weight < records->heap->array[adj->neighbors[i].vertex]->weight) { decreasePriority(records->heap, adj->neighbors[i].vertex, weight); records->predecessors[adj->neighbors[i].vertex] = min->toVertex; } } } } return makePath(records->tree, endVertex, startVertex);
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T04:26:00.412Z
Question from Code
v2
what algorithm does this use
Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { HeapNode *min = extractMin(records->heap); records->finished[min->edge.toVertex] = true; if (min->edge.fromVertex != min->edge.toVertex) { addTreeEdge(records, records->numTreeEdges, min->edge.fromVertex, min->edge.toVertex, min->edge.weight); } AdjList *neighbors = graph->vertices[min->edge.toVertex]; for (int i = 0; i < neighbors->numNeighbors; i++) { if (!records->finished[neighbors->neighbors[i].id]) { int newWeight = neighbors->neighbors[i].weight; int oldWeight = getWeight(records->heap, neighbors->neighbors[i].id); if (newWeight < oldWeight) { decreasePriority(records->heap, neighbors->neighbors[i].id, newWeight); records->predecessors[neighbors->neighbors[i].id] = min->edge.toVertex; } } } } return records->tree; }
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T05:11:58.221Z
Question from Code
v2
what algorithm does this use
Records *records = initRecords(graph, startVertex); while (!isEmpty(records->head)) { HeapNode min = extractMin(records->heap); records->finished[min.id] = true; addTreeEdge(records, records->numTreeEdges, min.id, records->predecessors[min.id], min.priority); AdjList *neighbors = graph->vertices[min.id]; while (neighbors != NULL) { int maybe_shorter = min.priority + neighbors->edge->weight; int index = records->heap->indexMap[neighbors->edge->toVertex]; if (records->finished[neighbors->edge->toVertex] == false && maybe_shorter < records->heap->arr[index].priority) { decreasePriority(records->heap, neighbors->edge->toVertex, maybe_shorter) records->predecessors[neighbors->edge->toVertex] = min.id; } neighbors = neighbors->next; } }
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T05:40:57.079Z
Question from Code
v2
what algorithm does this use
Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { Heapnode min = extractMin(records->heap); records->finished[min.id] = true; addTreeEdge(records, records->numTreeEdges, min.id, records->predecessors[min.id], min.priority); AdjList *neighbors = graph->vertices[min.id]; while (neighbors != NULL) { if (records->finished[neighbors->edge->toVertex] == false) { if (neighbors->edge->weight < records->heap->arr[records->heap->indexMap[neighbors->edge->toVertex]].priority) { decreasePriority(records->heap, neighbors->edge->toVertex, neighbors->edge->weight); records->predecessors[neighbors->edge->toVertex] = min.id; } } } } return records->tree;
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T17:43:24.346Z
Question from Code
v2
what algorithm is being implemented here
Records *asdfg123 = initRecords(graph, startVertex); while (!isEmpty(asdfg123->heap)) { HeapNode min = extractMin(asdfg123->heap); asdfg123->finished[min.id] = true; addTreeEdge(asdfg123, asdfg123->numTreeEdges, min.id, asdfg123->predecessors[min.id], min.priority); AdjList *neighbours = graph->vertices[min.id]; while (neighbours != NULL) { if (asdfg123->finished[neighbours->edge->toVertex] == false) { int index = asdfg123->heap->arr[neighbours->edge->toVertex] if (neighbours->edge->weight < asdfg123->heap->arr[index].priority) { decreasePriority(asdfg123->heap, neighbours->edge->toVertex, neighbours->edge->weight); asdfg123->predecessors[neighbours->edge->toVertex] = min.id; } } neighbours = neighbours->next; } } return asdfg123->tree;
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T17:44:14.425Z
Question from Code
v2
what algorithm is being used here
Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { HeapNode min = extractMin(records->heap); records->finished[min.id] = true; addTreeEdge(records, records->numTreeEdges, min.id, records->predecessors[min.id], min.priority); AdjList *neighbors = graph->vertices[min.id]; while (neighbors != NULL) { int maybe_shorter = min.priority + neighbors->edge->weight; int index = records->heap->indexMap[neighbors->edge->toVertex]; if (records->finished[neighbors->edge->toVertex] == false && maybe_shorter < records->heap->arr[index].priority) { decreasePriority(records->heap, neighbors->edge->toVertex, maybe_shorter) records->predecessors[neighbors->edge->toVertex] = min.id; } neighbors = neighbors->next; } } return records->tree;
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T17:57:02.682Z
Question from Code
v2
which algorithm is (1) using and which algorithm is (2) using?
(1) Records *asdfg123 = initRecords(graph, startVertex); while (!isEmpty(asdfg123->heap)) { HeapNode min = extractMin(asdfg123->heap); asdfg123->finished[min.id] = true; addTreeEdge(asdfg123, asdfg123->numTreeEdges, min.id, asdfg123->predecessors[min.id], min.priority); AdjList *neighbours = graph->vertices[min.id]; while (neighbours != NULL) { if (asdfg123->finished[neighbours->edge->toVertex] == false) { int index = asdfg123->heap->arr[neighbours->edge->toVertex] if (neighbours->edge->weight < asdfg123->heap->arr[index].priority) { decreasePriority(asdfg123->heap, neighbours->edge->toVertex, neighbours->edge->weight); asdfg123->predecessors[neighbours->edge->toVertex] = min.id; } } neighbours = neighbours->next; } } return asdfg123->tree; (2) Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { HeapNode min = extractMin(records->heap); records->finished[min.id] = true; addTreeEdge(records, records->numTreeEdges, min.id, records->predecessors[min.id], min.priority); AdjList *neighbors = graph->vertices[min.id]; while (neighbors != NULL) { int maybe_shorter = min.priority + neighbors->edge->weight; int index = records->heap->indexMap[neighbors->edge->toVertex]; if (records->finished[neighbors->edge->toVertex] == false && maybe_shorter < records->heap->arr[index].priority) { decreasePriority(records->heap, neighbors->edge->toVertex, maybe_shorter) records->predecessors[neighbors->edge->toVertex] = min.id; } neighbors = neighbors->next; } } return records->tree;
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T17:58:25.132Z
Question from Code
v2
what algorithm is this
Records *records = initRecords(graph, startVertex); while (!isEmpty(records->heap)) { HeapNode min = extractMin(records->heap); records->finished[min.id] = true; addTreeEdge(records, records->numTreeEdges, min.id, records->predecessors[min.id], min.priority); AdjList *neighbors = graph->vertices[min.id]; while (neighbors != NULL) { int maybe_shorter = min.priority + neighbors->edge->weight; int index = records->heap->indexMap[neighbors->edge->toVertex]; if (records->finished[neighbors->edge->toVertex] == false && maybe_shorter < records->heap->arr[index].priority) { decreasePriority(records->heap, neighbors->edge->toVertex, maybe_shorter) records->predecessors[neighbors->edge->toVertex] = min.id; } neighbors = neighbors->next; } } return records->tree;
null
null
63c647ec5f004bf4898cf7d4
2023-03-23T17:59:01.018Z
Question from Code
v2
what algorithm is this
Records *asdfg123 = initRecords(graph, startVertex); while (!isEmpty(asdfg123->heap)) { HeapNode min = extractMin(asdfg123->heap); asdfg123->finished[min.id] = true; addTreeEdge(asdfg123, asdfg123->numTreeEdges, min.id, asdfg123->predecessors[min.id], min.priority); AdjList *neighbours = graph->vertices[min.id]; while (neighbours != NULL) { if (asdfg123->finished[neighbours->edge->toVertex] == false) { int index = asdfg123->heap->arr[neighbours->edge->toVertex] if (neighbours->edge->weight < asdfg123->heap->arr[index].priority) { decreasePriority(asdfg123->heap, neighbours->edge->toVertex, neighbours->edge->weight); asdfg123->predecessors[neighbours->edge->toVertex] = min.id; } } neighbours = neighbours->next; } } return asdfg123->tree;
null
null
63c647ec5f004bf4898cf7d4
2023-04-08T22:22:35.660Z
Explain Code
v2
null
import web_resource as web_r import os import threading import youtube_api import util import os import google.auth import datetime from googleapiclient.discovery import build from youtube_transcript_api import YouTubeTranscriptApi class YouTubeAPI(web_r.web_results) : def result_from_youtube(self, related_questions:dict)->dict: "" " Given questions as a list of related questions to a user input question, return youtube video captions by searching the sub - questions on youtube input:a dictionary with a user input question as key and sub - questions as value return :a dictionary with following format: {"result" : [{"question" : "What is the best way to learn Python?", "question_list" : [{"name" : "What is the best way to learn Python?", "url" : "https: " content ": " I have been learning Python for a few months no " }, {... }, ...] }] } question:the user input question(key) question_list:name:one of the questions in the input url:the youtube video in answer to that question content:video caption.Should be after removing stop words "" " ##loop though questions and call youtube api on each result = self.search_youtube_transcript("") #collect result and remove stop words result = util.remove_stopwords(result) result_list =[] for key, value in related_questions.items() :question_list =[] for question in value:question_list.append({"name" :question, "url" : "", "content" :result[question] }) result_list.append({"question" :key, "question_list" :question_list }) return {"result" :result_list } pass
null
null
63c647ec5f004bf4898cf7d9
2023-01-17T22:50:52.779Z
Explain Code
v1
null
int main(int argc, char **argv) { if (argc == 2){ int c; enum { START, SAW_NL, SAW_TWO_NL } state = START; while ((c = getchar()) != EOF) { if (c == 10){ if (state == START){ putchar(c); state = SAW_NL; }else if (state == SAW_NL){ putchar(c); state = SAW_TWO_NL; } }else{ state = START; putchar(c); } }return (0); }else{ fprintf(stderr, "usage: squ format error\n"); return (1); } }
null
null
63c647ee5f004bf4898cf7ed
2023-01-17T19:22:57.773Z
Help Fix Code
v1
null
#include <stdio.h> int main(){ char phone[11]; int d; int scanf_return; scanf("%s", phone); // getting first input int err = 0; // variable for return value of program do{ scanf_return = scanf("%d", &d); if (d == -1){ printf("%s\n", phone); } else if (d<-1 || d>9){ printf("ERROR\n"); err = 1; } else if (d>=0 && d<10){ printf("%c\n", phone[d]); } } while(scanf_return != EOF); return err; }
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
63c647ee5f004bf4898cf7ed
2023-01-17T19:24:27.506Z
Help Fix Code
v1
null
#include <stdio.h> int main(){ char phone[11]; int d; int scanf_return; scanf("%s", phone); // getting first input int err = 0; // variable for return value of program do{ scanf_return = scanf("%d", &d); if (d == -1){ printf("%s\n", phone); } else if (d<-1 || d>9){ printf("ERROR\n"); err = 1; } else if (d>=0 && d<10){ printf("%c\n", phone[d]); } } while(scanf_return != EOF); return err; }
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.
null
63c647ee5f004bf4898cf7ed
2023-01-21T00:05:31.760Z
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 Sdud[31]; int Idud; scanf("%s %d", Sdud, &Idud); // Getting rid of the first line of stdin int size; int count = 0; if (argc == 2){ int scanf_return; do{ printf("hi"); scanf_return = scanf("%s %d %s %s %d %d %s %s %s", Sdud, &Idud, Sdud, Sdud, &size, &Idud, Sdud, Sdud, Sdud); // Stopping the loop from running if stdin is closed if (size > strtol(argv[2], NULL, 10)){ count++; } } while(scanf_return != EOF); } printf("%d", count); // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. return 0; } int check_permissions(char *actual, char *required){ int flag = 0; for (int i=0; i<9; i++){ if (required[i] != '-' && required[i] != actual[i]){ flag = 1; } } return flag; }
null
null
63c647ee5f004bf4898cf7ed
2023-01-21T00:06:21.115Z
Question from Code
v1
why am I getting a segmentation fault
#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 Sdud[31]; int Idud; scanf("%s %d", Sdud, &Idud); // Getting rid of the first line of stdin int size; int count = 0; if (argc == 2){ int scanf_return; do{ printf("hi"); scanf_return = scanf("%s %d %s %s %d %d %s %s %s", Sdud, &Idud, Sdud, Sdud, &size, &Idud, Sdud, Sdud, Sdud); // Stopping the loop from running if stdin is closed if (size > strtol(argv[2], NULL, 10)){ count++; } } while(scanf_return != EOF); } printf("%d", count); // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. return 0; } int check_permissions(char *actual, char *required){ int flag = 0; for (int i=0; i<9; i++){ if (required[i] != '-' && required[i] != actual[i]){ flag = 1; } } return flag; }
null
null
63c647f05f004bf4898cf7f7
2023-01-28T19:59:59.714Z
Help Fix Code
v1
null
#include <stdio.h> #include <stdlib.h> #include <string.h> // TODO: Implement a helper named check_permissions that matches the prototype below. int check_permissions(const char *input_permissions, const char *required_permissions) { for (int i = 0; i < 9; i++) { if (required_permissions[i] == '-') { continue; } if (required_permissions[i] != input_permissions[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; } // Process the command line arguments long size = strtol(argv[1], NULL, 10); char *required_permissions = argv[2]; // Initialize the variables used in the loop int count = 0; char input_permissions[10]; char input_size_str[10]; long input_size; // int i = 0; int permissions; // Skip the first line of ls -l scanf("%*s %*d"); // Scan each value from ls -l while (scanf("%s %*d %*s %*s %s %*s %*d %*s %*s", input_permissions, input_size_str) != EOF) { // Check if there are two command line arguments // Therefore checking permissions and size input_size = strtol(input_size_str, NULL, 10); if (argc == 3) { // Check if it is the first item of a line // if (i % 9 == 0) { if (check_permissions(&input_permissions[1], required_permissions) == 1) { permissions = 1; } else { permissions = 0; } // } //Check if it is the fifth item of a line // if (i % 9 == 4) { // Check if the permissions pass if (permissions == 1) { if (input_size > size) { count++; } permissions = 0; } // } } else { // Only checking if the size is larger than the input // Check if it is the fifth item of a line // if (i % 9 == 4) { // printf("%s\n", input_permissions); if (input_size > size) { count++; } // } } // i++; } printf("%d\n", count); return 0; }
take input from ls -l terminal command as well as one or two command line arguments and return the number of files greater in size
null
63c647f05f004bf4898cf7f7
2023-02-08T02:49:10.136Z
General Question
v1
How do you printf a date of time_t
null
null
null
63c647f05f004bf4898cf7f7
2023-02-08T04:01:53.964Z
Question from Code
v1
The compiler is saying that this is invalid and that a long type is necessary
new_post->date = time(NULL);
null
null
63c647f05f004bf4898cf7f7
2023-02-08T04:02:41.050Z
Question from Code
v1
new_post->date is of type time_t but this line of code is being flagged as an error and invalid
new_post->date = time(NULL);
null
null
63c647f05f004bf4898cf7f7
2023-02-08T05:13:49.450Z
Question from Code
v1
Why is there a segmenation fault
int make_post(const User *author, User *target, char *contents) { // Check if either User pointer is NULL if (author == NULL || target == NULL) { return 2; } // Check if users exist but are not friends int found = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (target->friends[i] == author) { found = 1; break; } } if (found == 0) { return 1; } // Make a new post Post *new_post = malloc(sizeof(Post)); strncpy(new_post->author, author->name, MAX_NAME); new_post->contents = contents; time(new_post->date); printf("%s", ctime(new_post->date)); new_post->next = target->first_post; target->first_post = new_post; return 0; }
null
null
63c647f05f004bf4898cf7f7
2023-02-08T05:21:16.705Z
Question from Code
v1
What is causing a segmentation fault
int make_post(const User *author, User *target, char *contents) { // Check if either User pointer is NULL if (author == NULL || target == NULL) { return 2; } // Check if users exist but are not friends int found = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (target->friends[i] == author) { found = 1; break; } } if (found == 0) { return 1; } // Make a new post Post *new_post = malloc(sizeof(Post)); strncpy(new_post->author, author->name, MAX_NAME); new_post->contents = malloc(strlen(contents)); strncpy(new_post->contents, contents, strlen(contents)); free(contents); time(new_post->date); printf("%s", ctime(new_post->date)); new_post->next = target->first_post; target->first_post = new_post; return 0; }
null
null
63c647f05f004bf4898cf7f7
2023-02-08T05:22:11.042Z
Question from Code
v1
what is line 26 doing
int make_post(const User *author, User *target, char *contents) { // Check if either User pointer is NULL if (author == NULL || target == NULL) { return 2; } // Check if users exist but are not friends int found = 0; for (int i = 0; i < MAX_FRIENDS; i++) { if (target->friends[i] == author) { found = 1; break; } } if (found == 0) { return 1; } // Make a new post Post *new_post = malloc(sizeof(Post)); strncpy(new_post->author, author->name, MAX_NAME); new_post->contents = malloc(strlen(contents)); strncpy(new_post->contents, contents, strlen(contents)); free(contents); time(new_post->date); printf("%s", ctime(new_post->date)); new_post->next = target->first_post; target->first_post = new_post; return 0; }
null
null
63c647f05f004bf4898cf7f7
2023-02-10T21:13:21.494Z
General Question
v1
What are the values of an initialized array
null
null
null
63c647f15f004bf4898cf801
2023-01-20T18:40:07.189Z
Explain Code
v1
null
scanf
null
null
63c647f15f004bf4898cf801
2023-01-27T18:45:23.039Z
Explain Code
v1
null
int *arr[2];
null
null
63c647f15f004bf4898cf801
2023-02-09T22:36:18.742Z
Explain Code
v1
null
String.join()
null
null
63c647f15f004bf4898cf801
2023-02-09T22:38:23.931Z
Explain Code
v1
null
String.concat()
null
null
63c647f15f004bf4898cf801
2023-02-09T22:47:06.926Z
General Question
v1
How to make string copy
null
null
null
63c647f15f004bf4898cf801
2023-02-10T21:29:11.135Z
Explain Code
v1
null
strtol
null
null
63c647f15f004bf4898cf801
2023-02-10T22:05:39.304Z
General Question
v1
what is struct
null
null
null
63c647f15f004bf4898cf801
2023-02-10T22:06:05.271Z
General Question
v1
waht is stored in struct
null
null
null
63c647f15f004bf4898cf806
2023-02-04T01:02:00.484Z
General Question
v1
what is the syntax for copying a string
null
null
null
63c647f15f004bf4898cf806
2023-02-04T01:07:55.634Z
Help Fix Code
v1
null
#include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters that were removed. If s has n or fewer characters, s is unchanged and the function returns 0. For example, if s is the string "function" and n is 3, then truncate() changes s to the string "fun" and returns 5. */ int truncate(char *s, int n){ char rand[n]; int charcount = 0; strncpy(rand, s, sizeof(rand)); } int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "Usage: truncate number string\n"); return 1; } int amt = strtol(argv[1], NULL, 10); char *target = argv[2]; int soln_val = truncate(target, amt); printf("%d %s\n", soln_val, target); return 0; }
truncate input at n
null
63c647f15f004bf4898cf806
2023-02-04T01:12:56.601Z
Help Fix Code
v1
null
#include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters that were removed. If s has n or fewer characters, s is unchanged and the function returns 0. For example, if s is the string "function" and n is 3, then truncate() changes s to the string "fun" and returns 5. */ int truncate(char *s, int n){ char rand[n]; int charcount = 0; strncpy(rand, s, sizeof(rand)); rand[sizeof(rand)]= '\0'; } int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "Usage: truncate number string\n"); return 1; } int amt = strtol(argv[1], NULL, 10); char *target = argv[2]; int soln_val = truncate(target, amt); printf("%d %s\n", soln_val, target); return 0; }
truncate string at n
null
63c647f15f004bf4898cf806
2023-02-04T01:14:36.581Z
Help Fix Code
v1
null
#include <stdlib.h> #include <stdio.h> #include <string.h> /* Write a function named truncate() that takes a string s and a non-negative integer n. If s has more than n characters (not including the null terminator), the function should truncate s at n characters and return the number of characters that were removed. If s has n or fewer characters, s is unchanged and the function returns 0. For example, if s is the string "function" and n is 3, then truncate() changes s to the string "fun" and returns 5. */ int truncate(char *s, int n){ char rand[n]; int charcount = 0; strncpy(rand, s, sizeof(rand)); rand[sizeof(rand)]= '\0'; } int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "Usage: truncate number string\n"); return 1; } int amt = strtol(argv[1], NULL, 10); char *target = argv[2]; int soln_val = truncate(target, amt); printf("%d %s\n", soln_val, target); return 0; }
truncate s at n
null
63c647f15f004bf4898cf806
2023-02-14T03:21:32.516Z
Help Fix Code
v1
null
int create_user(const char *name, User **user_ptr_add) { User *new_user = malloc(sizeof(User)); strcpy(new_user->name, name); new_user->next = NULL; memset(new_user->friends, 0, MAX_FRIENDS * sizeof(new_user -> friends[0])); if(user_ptr_add == NULL){ *user_ptr_add = new_user; } else if(strlen(name)>MAX_NAME){ return 2; } User *curr = *user_ptr_add; while(curr != NULL){ if(strcmp(curr->name, name) ==0 ){ return 1; } curr = curr->next; } curr->next = new_user; return 0; }
the linked list tail insertion is not working
null
63c647f15f004bf4898cf806
2023-02-15T22:50:52.680Z
Help Fix Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { User *curr = head; User *user1 = NULL; User *user2 = NULL; //traverses through list, assigns curr to user 1 and user2 if(strcmp(name1, name2)==0){ return 3; } else{ while(curr != NULL){ if(strcmp(curr ->name, name1)==0 ){ user1 = curr; } if(strcmp(curr ->name, name2)==0 ){ user2 = curr; } curr= curr->next; } if(user1 == NULL || user2 ==NULL){ return 4; } else{ for(int x =0;x<=MAX_FRIENDS;x++){ if(strcmp(user1->friends[x]->name, name2)==0){ return 1; } } for(int i =0; i<=MAX_FRIENDS; i++){ if(user1->friends[i]==0){ user1->friends[i]= user2; break; } else{ return 2; } } for(int j= 0;j<=MAX_FRIENDS;j++){ if(user2->friends[j]==0){ user2->friends[j]= user1; break; } else{ return 2; } } return 0; } } }
replace first 0 in friends of User name1 with User name2 and replace first 0 in friends of User name2 with User name1
null
63c647f15f004bf4898cf806
2023-02-15T22:53:45.704Z
Help Fix Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { User *curr = head; User *user1 = NULL; User *user2 = NULL; //traverses through list, assigns curr to user 1 and user2 if(strcmp(name1, name2)==0){ return 3; } else{ while(curr != NULL){ if(strcmp(curr ->name, name1)==0 ){ user1 = curr; } if(strcmp(curr ->name, name2)==0 ){ user2 = curr; } curr= curr->next; } if(user1 == NULL || user2 ==NULL){ return 4; } else{ for(int x =0;x<MAX_FRIENDS;x++){ if(strcmp(user1->friends[x]->name, name2)==0){ return 1; } } for(int i =0; i<MAX_FRIENDS; i++){ if(user1->friends[i]==0){ user1->friends[i]= user2; break; } else{ return 2; } } for(int j= 0;j<MAX_FRIENDS;j++){ if(user2->friends[j]==0){ user2->friends[j]= user1; break; } else{ return 2; } } return 0; } } }
replace first 0 in friend array of User name1 with User name2 and replace the first 0 in friend array of User name 2 with User name1
null
63c647f15f004bf4898cf806
2023-02-15T23:34:08.328Z
Help Fix Code
v1
null
memset(new_user->friends, 0, MAX_FRIENDS * sizeof(new_user -> friends[0]));
make all elements in new_user ->friends a 0
null
63c647f15f004bf4898cf806
2023-02-15T23:37:58.571Z
General Question
v1
how to cast const User struct to User struct
null
null
null
63c647f15f004bf4898cf806
2023-02-15T23:42:58.905Z
Help Fix Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { User *curr = head; User *user1 = NULL; User *user2 = NULL; int found_zero = 1; //traverses through list, assigns curr to user 1 and user2 if(strcmp(name1, name2)==0){ return 3; } else{ while(curr != NULL){ if(strcmp(curr ->name, name1)==0 ){ user1 = curr; } if(strcmp(curr ->name, name2)==0 ){ user2 = curr; } curr= curr->next; } if(user1 == NULL || user2 ==NULL){ return 4; } else{ for(int x =0;x<MAX_FRIENDS;x++){ if(strcmp(user1->friends[x]->name, name2)==0){ return 1; } } for(int i =0; i<MAX_FRIENDS; i++){ if(user1->friends[i]==0){ user1->friends[i]= user2; break; } else{ found_zero = 0; } } for(int j= 0;j<MAX_FRIENDS;j++){ if(user2->friends[j]==0){ user2->friends[j]= user1; break; } else{ found_zero = 0; } } if(found_zero ==0){ return 2; } else{ return 0; } } } }
replace first 0 in friends array of struct User name1 with struct User name2 and replace first 0 in friends array of struct User name2 with struct User name1
null
63c647f15f004bf4898cf806
2023-02-15T23:50:33.454Z
Help Fix Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { User *curr = head; User *user1 = NULL; User *user2 = NULL; int *found_zero = 1; //traverses through list, assigns curr to user 1 and user2 if(strcmp(name1, name2)==0){ return 3; } else{ while(curr != NULL){ if(strcmp(curr ->name, name1)==0 ){ user1 = curr; } if(strcmp(curr ->name, name2)==0 ){ user2 = curr; } curr= curr->next; } if(user1 == NULL || user2 ==NULL){ return 4; } else{ for(int x =0;x<MAX_FRIENDS;x++){ if(strcmp(user1->friends[x]->name, name2)==0){ return 1; } } for(int i =0; i<MAX_FRIENDS; i++){ if(user1->friends[i]==0){ user1->friends[i]= user2; break; } else{ found_zero = 0; } } for(int j= 0;j<MAX_FRIENDS;j++){ if(user2->friends[j]==0){ user2->friends[j]= user1; break; } else{ found_zero = 0; } } if(found_zero ==0){ return 2; } else{ return 0; } } } }
replace first 0 in friends array of struct User name1 with struct User name2 and replace first 0 in friends array of struct User name2 with struct User name1
null
63c647f15f004bf4898cf806
2023-02-15T23:51:48.418Z
Help Fix Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { User *curr = head; User *user1 = NULL; User *user2 = NULL; int found_zero = 1; //traverses through list, assigns curr to user 1 and user2 if(strcmp(name1, name2)==0){ return 3; } else{ while(curr != NULL){ if(strcmp(curr ->name, name1)==0 ){ user1 = curr; } if(strcmp(curr ->name, name2)==0 ){ user2 = curr; } curr= curr->next; } if(user1 == NULL || user2 ==NULL){ return 4; } else{ for(int x =0;x<MAX_FRIENDS;x++){ if(strcmp(user1->friends[x]->name, name2)==0){ return 1; } } for(int i =0; i<MAX_FRIENDS; i++){ if(user1->friends[i]==0){ user1->friends[i]= user2; break; } else{ found_zero = 0; } } for(int j= 0;j<MAX_FRIENDS;j++){ if(user2->friends[j]==0){ user2->friends[j]= user1; break; } else{ found_zero = 0; } } if(found_zero ==0){ return 2; } else{ return 0; } } } }
replace first 0 in friends array of struct User name1 with struct User name2 and replace first 0 in friends array of struct User name2 with struct User name1
null
63c647f15f004bf4898cf806
2023-02-15T23:57:44.599Z
Help Fix Code
v1
null
int make_friends(const char *name1, const char *name2, User *head) { User *curr = head; User *user1 = NULL; User *user2 = NULL; int found_zero = 1; //traverses through list, assigns curr to user 1 and user2 if(strcmp(name1, name2)==0){ return 3; } else{ while(curr != NULL){ if(strcmp(curr ->name, name1)==0 ){ user1 = curr; } if(strcmp(curr ->name, name2)==0 ){ user2 = curr; } curr= curr->next; } if(user1 == NULL || user2 ==NULL){ return 4; } else{ for(int x =0;x<MAX_FRIENDS;x++){ if(strcmp(user1->friends[x]->name, name2)==0){ return 1; } } for(int i =0; i<MAX_FRIENDS; i++){ if(user1->friends[i]==0){ user1->friends[i]= user2; break; } else{ found_zero = 0; } } for(int j= 0;j<MAX_FRIENDS;j++){ if(user2->friends[j]==0){ user2->friends[j]= user1; break; } else{ found_zero = 0; } } if(found_zero ==0){ return 2; } else{ 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 0 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.
null
63c647f15f004bf4898cf806
2023-02-16T00:34:32.298Z
General Question
v1
when do you use malloc
null
null
null
63c647f15f004bf4898cf806
2023-02-16T00:34:55.794Z
General Question
v1
when should you use malloc for a struct
null
null
null
63c647f15f004bf4898cf806
2023-02-17T17:35:47.447Z
Help Fix Code
v1
null
int make_post(const User *author, User *target, char *contents) { //check if users are friends if(author != NULL && target != NULL){ for(int i=0; i>0; i++){ //users are friends if((strcmp(author->friends[i]->name, target->name)==0) && author->name[i]!=0){ Post *new_post = malloc(sizeof(Post)); new_post->contents = contents; strncpy(new_post->author, author->name, sizeof(new_post->author)); time_t *date = malloc(sizeof (*date)); time(&date); new_post->date= date; new_post->next = target->first_post; target->first_post = new_post; return 0; } //users aren't friends else{ return 1; } } } else{ return 2; } }
insert new post at head of User target and assign current date to the new post
null
63c647f15f004bf4898cf806
2023-02-17T17:37:36.892Z
Help Fix Code
v1
null
int make_post(const User *author, User *target, char *contents) { //check if users are friends if(author != NULL && target != NULL){ for(int i=0; i>0; i++){ //users are friends if((strcmp(author->friends[i]->name, target->name)==0) && author->name[i]!=0){ Post *new_post = malloc(sizeof(Post)); new_post->contents = contents; strncpy(new_post->author, author->name, sizeof(new_post->author)); time_t *date = malloc(sizeof (*date)); time(&date); new_post->date= date; new_post->next = target->first_post; target->first_post = new_post; return 0; } //users aren't friends else{ return 1; } } } else{ return 2; } }
assign current date and time to User target's date
null
63c647f15f004bf4898cf806
2023-02-17T18:04:20.449Z
Help Fix Code
v1
null
int make_post(const User *author, User *target, char *contents) { //check if users are friends if(author != NULL && target != NULL){ for(int i=0; i<MAX_FRIENDS; i++){ //users are friends if(author->friends[i]!=0){ if((strcmp(author->friends[i]->name, target->name)==0)){ Post *new_post = malloc(sizeof(Post)); new_post->contents = contents; strncpy(new_post->author, author->name, sizeof(new_post->author)); time_t *date = malloc(sizeof (*date)); time(date); new_post->date= date; new_post->next = target->first_post; target->first_post = new_post; return 0; } } //users aren't friends else{ return 1; } } } else{ return 2; } }
return 0 if success
null
63c647f15f004bf4898cf806
2023-02-17T18:45:23.384Z
Help Fix Code
v1
null
int delete_user(const char *name, User **user_ptr_del) { User *curr = *user_ptr_del; User *prev = NULL; // If head node itself holds the key to be deleted if (curr != NULL && curr->name == name) { *user_ptr_del = curr->next; // Changed head free(curr); // free old head } // Search for the key to be deleted, keep track of the // previous node as we need to change 'prev->next' while (curr != NULL && strcmp(curr->name, name)!=0) { prev = curr; curr = curr->next; } // If key was not present in linked list if (curr == NULL) return 1; // Unlink the node from linked list prev->next = curr->next; free(curr); // Free memory return 0; }
delete node with given name
null
63c647f15f004bf4898cf806
2023-02-17T18:48:04.070Z
Help Fix Code
v1
null
int delete_user(const char *name, User **user_ptr_del) { User *curr = *user_ptr_del; User *prev = NULL; // If head node itself holds the key to be deleted if (curr != NULL && strcmp(curr->name, name)==0) { *user_ptr_del = curr->next; // Changed head free(curr); // free old head } // Search for the key to be deleted, keep track of the // previous node as we need to change 'prev->next' while (curr != NULL && strcmp(curr->name, name)!=0) { prev = curr; curr = curr->next; } // If key was not present in linked list if (curr == NULL) return 1; // Unlink the node from linked list prev->next = curr->next; free(curr); // Free memory return 0; }
traverse linked list and delete node with given name
null
63c647f25f004bf4898cf810
2023-01-20T21:38:25.695Z
Help Fix Code
v1
null
#include <stdio.h> int main(){ char phone_num[11]; scanf("%s", phone_num); int a, contains_error = 0; while(1){ scanf("%d", &a); if(a == -1){ printf("%s\n", phone_num); }else if(a >= 0 && a <= 9){ printf("%c\n", phone_num[a]); }else{ printf("ERROR\n"); contains_error = 1; } } if(contains_error){ return 1; }else{ return 0; } }
null
null
63c647f25f004bf4898cf810
2023-01-20T21:53:10.925Z
General Question
v1
how do i detect the end of stdin
null
null
null
63c647f25f004bf4898cf810
2023-01-20T21:55:42.179Z
General Question
v1
how to i detect the end of stdin IN C CODE
null
null
null
63c647f25f004bf4898cf810
2023-01-20T21:56:48.934Z
General Question
v1
how to detect the end of stdin using scanf in C code
null
null
null
63c647f35f004bf4898cf815
2023-01-24T22:41:57.741Z
General Question
v1
How to separate a string by \n?
null
null
null
63c647f35f004bf4898cf81a
2023-01-27T01:21:32.335Z
Help Fix Code
v1
null
int **split_array(const int *s, int length) { int **arr = (int **)malloc(sizeof(int)*length); arr[0] = (int *) malloc(sizeof(int)* length/2); arr[1] = (int *) malloc(sizeof(int)* length/2); for(int i = 0; i < length; i++){ if(i%2 == 0){ arr[0][i] = s[i]; } if(i%2 == 1){ arr[1][i] = s[i]; } } return arr; }
How can I assign arr[0][i] to s[i]
null
63c647f35f004bf4898cf81a
2023-01-27T01:25:53.632Z
Help Fix Code
v1
null
int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(*strs,NULL,10); } return arr; }
how can I assign each arr[i] for each part of a long type variable.
null
63c647f35f004bf4898cf81a
2023-01-27T01:27:40.306Z
Help Fix Code
v1
null
int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs[i],NULL,10); } return arr; }
how can I assign each arr[i] from the strtol
null
63c647f35f004bf4898cf81a
2023-01-27T01:29:11.680Z
Help Fix Code
v1
null
int *build_array(char **strs, int size) { long i = strtol(strs,NULL,10); i[0] = 0; }
How can I assign i[0]
null
63c647f35f004bf4898cf81a
2023-01-27T01:30:55.376Z
Help Fix Code
v1
null
int *build_array(char **strs, int size) { long *arr = malloc(sizeof(long)*size); arr = strtol(strs,NULL,10); arr[0] = 0; }
How can I assign i[0]
null
63c647f35f004bf4898cf81a
2023-01-27T01:32:27.565Z
Help Fix Code
v1
null
int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); arr = strtol(strs,NULL,10); arr[0] = 0; }
How can I assign i[0]
null
63c647f35f004bf4898cf81a
2023-01-27T01:33:22.120Z
Help Fix Code
v1
null
int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); arr[0] = strtol(strs[0],NULL,10); }
How can I assign i[0]
null
63c647f35f004bf4898cf81a
2023-01-27T01:34:02.305Z
Help Fix Code
v1
null
int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs[i],NULL,10); } return arr; }
How can I assign i[0]
null
63c647f35f004bf4898cf81a
2023-01-27T01:34:26.170Z
Help Fix Code
v1
null
int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs[i],NULL,10); } return arr; }
How can I assign arr[0]
null
63c647f35f004bf4898cf81a
2023-01-27T01:34:57.398Z
Help Fix Code
v1
null
int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs,NULL,10); } return arr; }
How can I assign arr[0]
null
63c647f35f004bf4898cf81a
2023-01-27T01:35:28.665Z
Explain Code
v1
null
int *build_array(char **strs, int size) { int *arr = malloc(sizeof(int)*size); for(int i = 0; i< size; i++){ arr[i] = strtol(strs[i],NULL,10); } return arr; }
null
null
63c647f35f004bf4898cf81a
2023-01-28T20:24:08.228Z
Help Fix Code
v1
null
int check_permissions(char *file[9], char *required[9]) { for (int i = 0; i < 9; i++) { if (required[i] != "-") { if (file[i] != required[i]) { return 1; } } } return 0; }
How to compare required[i] with "-"
null
63c647f35f004bf4898cf81a
2023-01-28T20:27:14.725Z
Help Fix Code
v1
null
int check_permissions(char *file, char *required) { for (int i = 0; i < 9; i++) { if (required[i] != "-") { if (file[i] != required[i]) { return 1; } } } return 0; }
how can I get value of index i in the required
null
63c647f35f004bf4898cf81a
2023-01-28T21:15:26.395Z
General Question
v1
how can i extract permissions value from ls -l
null
null
null
63c647f35f004bf4898cf81a
2023-01-28T21:16:39.326Z
General Question
v1
how can I assign permissions form ls -l to a variable
null
null
null
63c647f35f004bf4898cf81a
2023-01-28T22:01:55.560Z
Question from Code
v1
Can access file's index which is the output from ls-l by file[i][4]
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 *file; scanf("%s", file) // TODO: Call check_permissions as part of your solution to count the files to // compute and print the correct value. int count = 0; for(int i = 0; i < sizeof(file); i++){ if(file[i][4] >= argc){ if(argv){ if(check_permissions(file[i][0],*argv) == 0){ count += 1; } } else{ count += 1; } } } printf("%d\n",count); return 0; }
null
null
63c647f35f004bf4898cf81a
2023-01-28T22:02:42.805Z
General Question
v1
Can assign the output from ls-l to a string?
null
null
null
63c647f35f004bf4898cf81a
2023-01-28T22:03:32.300Z
General Question
v1
How to user scanf for the output of ls-l
null
null
null
63c647f35f004bf4898cf81a
2023-01-28T22:04:26.405Z
General Question
v1
The type of output of ls-l
null
null
null
63c647f35f004bf4898cf81a
2023-01-29T01:20:37.815Z
General Question
v1
How to know how many command-line arguments are being given?
null
null
null
63c647f35f004bf4898cf81a
2023-01-29T01:23:49.104Z
General Question
v1
how can I use `argc` ?
null
null
null
63c647f35f004bf4898cf81a
2023-02-01T21:07:01.667Z
General Question
v1
How to modify a string literal?
null
null
null