Nios/structfind

From ASMBits

Consider the following struct:

struct ProfitList {
	unsigned int product_id;
	int profit;
};

An array of this struct can be used as a list of products (each with a product id) and the profit for selling each item.


struct ProductInfo {
	unsigned int product_id;
	char *product_name;
};

An array of struct ProductInfo maps each product_id with its name. For this problem, it is not important whether product_name is null or actually points to a valid string.

Given an array of ProfitList, find the product with the maximum profit (profit can be negative). There will be at least one entry in this array. If there is more than one product with maximum profit, return the first one.

Then, look up the product_id in an array of ProductInfo and return the product_name for that product. If the maximum-profit product isn't in the ProductInfo list, return 0.


char* find (struct ProfitList* profit_array, unsigned int profit_array_entries, struct ProductInfo* info_array, unsigned int info_array_entries);


Expected solution length: Around 25 lines.

Sample Input

[See sample input below]

Sample Output

r2=0x210

Write your solution here

Upload a source file...