When I compile and run the program, it says: In function 'addToTheEnd': [Warning] initialization from incompatible pointer type //and it points to this line -> knot_t *current = start;
How to fix it? I'm new to C, so I don't understand what should be changed. I tried to understand it but I couldn't. My goal is to get some output out of this program when I run it, but nothing displays.
#include <stdio.h>
#include <stdlib.h>
typedef struct knot {
int number;
struct knot *next;
} knot_t;
int addToTheEnd(knot_t **start, int value) {
knot_t *new_ = (knot_t *)malloc(sizeof(knot_t));
if (new_ == NULL) {
return 1;
}
new_ -> number = value;
new_ -> next = NULL;
if (start == NULL) {
*start = new_;
} else {
knot_t *current = start;
while (current -> next != NULL) {
current = current -> next;
}
current -> next = new_;
}
return 0;
}
void printList(knot_t *start) {
knot_t *current = start;
while (current != NULL) {
printf("%d ", current->number);
current = current -> next;
}
}
void clearList(knot_t *start) {
knot_t *current = start;
while (current != NULL) {
knot_t* trenutni = current;
current = current -> next;
free(trenutni);
}
}
int main() {
knot_t *start = NULL;
int i = 0;
for (i = 0; i < 10; i++) {
if(addToTheEnd(&start, i)) {
printf("Fail\n");
return EXIT_FAILURE;
}
}
printList(start);
clearList(start);
return EXIT_SUCCESS;
}