I seem to not be able to find the problem to make the program work. C is telling me "error: Invalid operands to binary != 'grocerylist' (aka struct grocerylist) and 'int' When i try to solve this problem other bugs pop out, can anyone see other problems in this code except for the bug I posted about?
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
typedef struct grocerylist
{
char name[MAX];
float ammount;
char unit[MAX];
} grocerylist;
struct grocerylist * enterItems(int arr)
{
grocerylist * itemtolist;
itemtolist = (grocerylist*)malloc(sizeof(grocerylist)*arr);
if (*itemtolist != 0)
{
int i;
for(i = 0; i < arr; i++)
{
printf("Enter item name: /n");
scanf("%c", (itemtolist[i]).name);
printf("Enter ammount of item: /n");
scanf("%f", &(itemtolist[i]).ammount);
printf("Enter unit of item: /n");
scanf("%c", (itemtolist[i]).unit);
}
}
return itemtolist;
}
void printShoppingList(grocerylist *itemtolist, int arr)
{
int i;
for (i = 0; i < arr; i++)
{
printf("%s, %f, %s", itemtolist[i].name, itemtolist[i].ammount,
itemtolist[i].unit);
}
}
int main(void)
{
int arr, number;
grocerylist * itemtolist;
while (number == 0)
{
printf("How many items would you like to add to your list? /n");
scanf("%i", &arr);
itemtolist = enterItems(arr);
printShoppingList(itemtolist, arr);
free(itemtolist);
printf("Do you want to enter another item. 0 for yes, 1 for no");
scanf("%i", &number);
}
return 0;
}