Reference no: EM13166696
how implement memory allocation with strings.
need to use a temporary variable to hold a string of
MAX_GENERATED_WORD_LENGTH characters which you will use to store the
string representing the word you are building. When this function returns, the temporary
variable should not be stored anymore in memory.
You will then iterate over the list of symbols provided to your function. This list is
implemented in an array named symbols of size nbSymbols. Each element of this array is
an int representing the atomic number of the element which symbol we want to use to spell a word.
The atomic numbers are to be used as parameter to the getElementSymbol function which will return the string representing this element's symbol.
These strings need to be concatenated to your temporary string in order to build the word represented
by the series of atomic numbers in the parameter symbols.
This is what I have so far:
char* elementsBuildWord(const int symbols[], int nbSymbols){
/* ROLE takes a list of elements' atomic numbers and allocate a new string made
of the symbols of each of these elements
PARAMETERS symbols an array of nbSymbols int which each represent the atomic number
of an element
nbSymbols symbols array's size
RETURN VALUE NULL if the array is of size <= 0
or if one of the symbols is not found by our getElementSymbol function
other the address of a newly allocated string representing the concatenation
of the names of all symbols
*/
if (nbSymbols <= 0){return NULL;}
if (!symbols) {return NULL;}
return NULL; // just here to let the project compile, implement your own version of this function
}