You shouldn't be setting a string to a number without casting. However the bigger problem is you allocate an array based on a non-initialized variable. You should really be reallocating that array every time the variable is changed. I wonder if it throws an error there since it is the first use in the code.