In this function, I trying to delete a product from a list. Visual Studio shows me a red line under
list->itemList[i].productName = list->itemList[i + 1].productName;
and
list->itemList[i].unit = list->itemList[i + 1].unit;
but not under
list->itemList[i].amount = list->itemList[i + 1].amount;
The productName
and unit
is char
, and the amount
is float
.
void removeItem(struct ShoppingList *list){
int itemToDelet;
while (1) {
for (int i = 0; i < list->length; i++) {
printf("%d. %s \t %.2f \t %s\n", i + 1, list->itemList[i].productName, list->itemList[i].amount, list->itemList[i].unit);
}
printf("\n\nWhich product do you want to remove? ");
scanf("%d", &itemToDelet);
if (itemToDelet <= list->length) {
for (int i = 0; i < list->length; i++) {
if (itemToDelet == i + 1) {
for (int i = 0; i < list->length; i++) {
list->itemList[i].productName = list->itemList[i + 1].productName;
list->itemList[i].amount = list->itemList[i + 1].amount;
list->itemList[i].unit = list->itemList[i + 1].unit;
list->length--;
}
break;
}
break;
}
}
else {
printf("\nThe list contains only %d items!", list->length);
}
break;
}
}