2 For simplicity an e mail address consist of six characters followed by

2 for simplicity an e mail address consist of six

This preview shows page 4 - 7 out of 10 pages.

2. For simplicity an e-mail address consist of six characters followed by @ followed by 2 characters (e.g., [email protected], [email protected]). 3. You can assume that if the @ symbol is found there is a valid e-mail address associated with it (i.e., six characters will precede @ and two will follow @). 4. If the str parameter is the empty string or NULL, the function will return 0 and perform no processing; otherwise the function will return 1. 5. You can assume the output parameter is large enough to fit the answer. 6. The output parameter will be a string. 7. If str does not have a @ symbol, set result to an empty string. 8. If possible, provide comments with your code (you will not receive extra points for providing comments). 9. The following driver (and output) illustrates the functionality of the function (feel free to ignore it if you know what to implement). The % represents the Unix prompt. Remember, your code must work for other strings (not just the one provided in the example). Driver #define MAX_LEN 80 int main() { char result[MAX_LEN + 1]; get_email("contact [email protected] by noon", result); printf("%s\n", result); return 0; } Output % a.out [email protected] %
Image of page 4
5 int get_email(const char *str, char result[]) DirectoryId:
Image of page 5
6 Problem #3 (Structures) The following definitions will be used for the questions below. A Storestructure represents a store that has a name and a set of orders (represented by an array of Orderstructures). An Orderstructure keeps track of the customer’s name associated with an order (cnamefield), the number of items in the order (num_of_itemsfield) and the total bill for the order (totalfield). The name of each item in the order is kept in the itemsarray. For this problem feel free to use functions from the string library (string.h), but notice that you may not add fields to the provided structures and you may not use malloc, calloc or any other dynamic memory allocation function. In addition, you may not add any auxiliary function. You will lose credit if your code is not efficient. For example, if something can be implement via one assignment statement and you use 4, you will lose credit.#define MAX_ITEMS 100 #define MAX_LEN 80 #define MAX_ORDERS 50typedef struct order { char cname[MAX_LEN + 1]; int num_of_items; char items[MAX_ITEMS][MAX_LEN + 1]; float total; } Order; typedef struct store { char name[MAX_LEN + 1]; int num_of_orders; Order orders[MAX_ORDERS]; } Store;1.(10 pts) Which of the expressions below will compile when they replace the comment /* CODE HERE */ in the following driver? Circle VALID or INVALID. int main() { Store store; Order order1, order2, *p = &order1; int answer; /* CODE HERE */ return 0; } a.store.name = NULL;/* VALID / INVALID */b.answer = (order1 == order2); /* VALID / INVALID */c.*p = order2; /* VALID / INVALID */d.order1.cname = order2.cname; /* VALID / INVALID */e.struct order k = order1; /* VALID /
Image of page 6
Image of page 7