Hi there.
Following my latest thread about queues, someone suggested me something to my code that I decided to also implement it on my linked-lists example but it gives me a warning. Though, it compiles and works...
Here's the code:
There's only one line with a comment which is the line that produces the warning and the comment itself is the warning.Code:#include <stdio.h> #include <stdlib.h> #include <time.h> #define MAX 10 typedef struct sList { int elem; struct sList *next; } List; List* insertList(List *l, int elem) { if(!l) { List *x = (List*)malloc(sizeof(List)); x->elem = elem; x->next = NULL; return x; } else { l->next = insertList(l->next, elem); return l; } } void printList(const List *l) { List *ptr = l; // warning: initialization discards qualifiers from pointer target type do { printf("%d", ptr->elem); ptr = ptr->next; if(ptr) printf(" -> "); } while(ptr); } int main() { List *l = NULL; int i, num; srand((unsigned)time(NULL)); printf("RANDOM: "); for(i = 0; i < MAX; i++) { num = rand() % 100 + 1; printf("%d ", num); l = insertList(l, num); } printf("\n\nLIST: "); printList(l); return 0; }
What does it mean and how can I get rid of it?



LinkBack URL
About LinkBacks




