Böyle bir yapı vardır:bağlı bir listedeki bir yapı içinde bir yapı yazdırma
typedef struct stockItem {
char *componentType;
char *stockCode;
int numOfItems;
int price;
} stockItem;
// declaration
stockItem *stockItem_new(char *componentType, char *stockCode, int numOfItems, int price);
Ve böyle bir yapı birçok stok öğeleri (bağlantılı liste) Bunlar
typedef struct inventory {
struct stockItem item;
struct inventory *next;
}inventory;
saklamak için her ikisi de farklı başlık dosyasında. Ben bağlantılı liste oluşturduk
, I, belirli veri bitlerini kapalı yazdırmak böyle istiyorum:
void outputData(){
// This temporarily takes the location of the structs in the
// linked list as we cycle through them to the end
struct inventory *myInv = pFirstNode;
printf("Current Inventory\n\n");
// Until the ptr reaches a value of NULL for next we'll
// keep printing out values
while(myInv != NULL){
// HERE IS MY PROBLEM HOW DO I PRINT OFF THE COMPONENTTYPE FROM THIS
printf("%s\n\n", myInv->item->compnentType);
// Switch to the next struct in the list
myInv = myInv->next;
}
}
DÜZENLEME:
stockItem *stockItem_new(char *componentType, char *stockCode, int numOfItems, int price){
// creates a new duration for the song
stockItem *item = (stockItem*)malloc(sizeof(stockItem));
// assigns the attributes
item->componentType = componentType;
item->stockCode = stockCode;
item->numOfItems = numOfItems;
item->price = price;
// returns it
return item;
}
"stockItem_new" kodunu görmemiz gerekiyor. –
Certaininly @AlterMann –
"malloc" in sonucunu C'ye yazmayın, ayrıca neden "stockItem_new" (işaretçiyi döndürür) varsa "Envanter" de bir işaretçi tutmak mı? (Bu beyan ile, 'item'' stockItem' için bir işaretçi olmadığı için 'item.compnentType' olacaktır. – crashmstr