This is the problem:

In this exercise you have to write a program to manage items in a super market.
Suppose that the data about each item includes:
• Item’s ID: ID of the item, it is an integer which ranges from 1 to 9999
• Item’s type: Its value is:
• 1 if the item is food
• 2 if the item is electrical good
• 3 if the item is household good
• Item’s price

1. Create a structure template that contains data of one item. Then use this template to declare an array
of structures that stores data of maximum 50 items.
2. Ask user to input the list of N items from the keyboard. Then print out the list of items on the screen.
3. Print out the title of the item which has maximum price.
Here is my source code

#define MAX 50

struct good 
   int id;
   int type;
   float price;
struct good item[MAX];
int n;
int pos;

void input()
{ char temp[40];
  int i;
  printf("how many items u want to store: "); scanf("%d",&n);
  for(i=0; i<n; i++)
    printf("\nItem %d: ",i+1);
      printf("\n id:");
    } while( (item[i].id<0) || (item[i].id>9999) );
    printf("\n Type: ");
       else if(strcmp(temp,"electrical")==0)
               else if(strcmp(temp,"household")==0)
    printf("\n Price: ");

void display()
  int i;
  for(i=0; i<n; i++)
    printf("Item %d: ",i+1);
    printf("\n id %d, type %d, price %f\n",item[i].id,item[i].type, item[i].price);

struct good price(struct good arr[])
  int i,pos;
  struct good temp;
  temp  = item[0];
  for(i=0; i<n; i++)
    if(temp.price < item[i].price)
    temp = item[i];
  return temp ;
void display_item(struct good *p)
  printf("\n id %d, type %d, price %f\n",p -> id, p -> type, p -> price);  

int main()
    struct good item_max;
    item_max =struct good price(item[MAX]);
    return 0;

to solve problem number 3, I use a function to find the item having max price , then print its details ,but I cannot passing the structure "item" found in function struct good price(struct good arr[]) to display_item function.
Please help me find the mistake!
Thanks a lot!

>Please help me find the mistake!
I suspect the mistake is a complete failure to study whatever book on C you have. Instead of trying to finish this exercise in one swell foop, perhaps you should be writing a simple skeleton that passes structures around. At least that way you'll fail on fundamental concepts much sooner and will have an easier time sorting things out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.