can you give an example of sorting?
in c..tnx!

There are many : Bubble Sort,Merge Sort,Quick Sort.

And yes "can you give" is one of the phrases you should use in this community only after you yourself do some work on it.Hope you have done it.

struct restaurant_t {
	char name[20];
	char add[20];
	char type[10];
	double cost[5];

}rest[8]={"ABC","Makati","150.00","Thai"},
	       {"DEF","Pasay","250.00","Asian"};



struct rest_t rest1[8];

main()
{
	char x;
	char temp;
	printf("Choose your food type: ");
	scanf("%s",&temp);
	for(x=0;x<=8;x++)
	{
		if(temp==rest[x].type)
		rest1[x]=rest[x];
	}
}

in this program when you type, example you type asian all the asian food will be shown

struct restaurant_t {
	char name[20];
	char add[20];
	char type[10];
	double cost[5];
}rest[8]={"ABC","Makati","150.00","Thai"},
	       {"DEF","Pasay","250.00","Asian"};

in this program when you type, example you type asian all the asian food will be shown

Hey be descriptive in your needs and ya if I am not wrong then the initialization of structure is not correct.For every array type you need to declare like this:

struct restaurant_t {
	char name[20];
	char add[20];
	char type[10];
	double cost[5];
};

struct restaurant_t rest[8]={{"ABC","Makati","150.00","Thai"},
	       {"DEF","Pasay","250.00","Asian"},{.......},{.......},{.......},{.......},{.......},{.......}};

or

struct restaurant_t {
	char name[20];
	char add[20];
	char type[10];
	double cost[5];
}rest[8]={{"ABC","Makati","150.00","Thai"},
	       {"DEF","Pasay","250.00","Asian"},{    }, {   },{  }};

Not the way you have done.

struct rest_t {
	char name[20];
	char add[20];
	char type[10];
	double cost[5];
}

struct rest_t rest[8]={{"ABC\tMakati\t250.00\tThai"},
	 	       {"DEF","Pasay","350.00","American"},
	 	       {"GHI","Manila","150.00","Asian"},
		       {"JKL","Muntinlupa","300.00","Thai"},
		       {"MNO","Paranaque","350.00","Thai"},
		       {"PQR","Manila","200.00","American"},
		       {"STU","Makati","400.00","Asian"},
		       {"VWX","Roxas blvd.","500.00","Asian"},
		       {"YZA","Manila","250.00","American"}};

main()
{
	char x;
	char temp;
	char rest1[x];

	printf("Choose your food type: ");
	scanf("%s",&temp);
	for(x=0;x<=8;x++)
	{
		if(temp==rest[x].type)
		rest1[x]=rest[x];
	}
}

that codes are incomplete..
there's an errors again in declaring.
too many types in declaration and too many initializers

struct rest_t {
	char name[20];
	char add[20];
	char type[10];
	double cost[5];
};

needs a semicolon at the end.

struct rest_t rest[9]={{"ABC","Makati","250.00","Thai"},
	 	       {"DEF","Pasay","350.00","American"},
	 	       {"GHI","Manila","150.00","Asian"},
		       {"JKL","Muntinlupa","300.00","Thai"},
		       {"MNO","Paranaque","350.00","Thai"},
		       {"PQR","Manila","200.00","American"},
		       {"STU","Makati","400.00","Asian"},
		       {"VWX","Roxas blvd.","500.00","Asian"},
		       {"YZA","Manila","250.00","American"}};

Trying to define 9 structs in an array that can only hold 8 (and those '\t's should have been quotes)

char x;
	char temp;
	char rest1[x];

x hasn't been given a value yet, so how big should rest1 be?

rest1[x]=rest[x];

You are trying to convert a rest_t structure into a single char?

i thought that you need to initialize a struct in same way you define it. double cost is last defined but is not initialized last

That is true, and you also cannot declare a double using quotes "". I strongly suggest you learn the basics of C first.

This article has been dead for over six months. Start a new discussion instead.