That's the task (should use copy by value semantics):
Here is my implementationCode:typedef struct { // street address char street[30]; // postal code int postalCode; } Address; /* * This function creates a new address with a certain street address * and a certain postal code. */ Address addressConstruct(const char *street, int postalCode); // Accessor for the street address. The caller // of this function must free() the return value when // he/she is done with it! char *addressGetStreet(Address addr);
Could someone tell me how to use DevC++ to detect memory leaks?Code:Address addressConstruct(const char *street, int postalCode) { Address add; strcpy(add.street, street); add.postalCode = postalCode; return add; } char *addressGetStreet(Address addr) { char* ch; ch = (char*)malloc((strlen(addr.street)+1)*sizeof(char)); strcpy(ch, addr.street); return ch; }
Thanks in advance.




Reply With Quote