#include <stdio.h>
void add_element(char object[20], int price);
struct linked_list {
char object[20];
int price;
struct shopping_list *next;
};
struct linked_list list = {"car", 15000, NULL};
struct linked_list *last = &list;
int main() {
add_element("snake", 340);
printf("%s", list.object);
return 0;
}
void add_element(char object[20], int price) {
struct linked_list new_element = {object, price, NULL};
}
ERROR:C Initialisierung macht Ganzzahl von Zeiger
warning: initialization makes integer from pointer without a cast [enabled by default]
struct linked_list new_element = {object, price, NULL};
wenn ich pass "Schlange" direkt funktioniert es LINKED_LIST new_element auf struct, aber Objekt übergeben nicht.
Sie wissen, dass Sie dem Funktionsaufruf falsche Versprechungen machen, richtig? –
Ändern Sie es in 'struct linked_list new_element = {" ", price, NULL}; strcpy (neues_element.objekt, objekt); ' – BLUEPIXY