I have a problem, when I want to go concatenating it is the variable of type string temp every time the cycle is repeated this variable is restarted. Why is this happening and what can I do to solve it?
void processData( int *digits, int digitLen ) {
//char numLetter[];
char temp[] = "";
int i,c,j;
if( digitLen >= 3 ) {
int m = digitLen - 2;
// restamos 2 porque solo nos interesan aquí los número
// a partir de 3 dígitos, es decir, a partir de 100
for( i = m, j = m - 1, c = 0; i >= 1; i--, j--, c++ ) {
int g = digits[c]-1; // take the number to add the unit
if( g == 0 )
continue;
strcat(temp,a[0][g]);
strcat(temp," ");
strcat(temp,a[3][j]);
strcat(temp," ");
}
strcat(temp,"and ");
}
printf("%s \n",temp);
}
I am doing a program that returns a number in letter, for that I want to go adding concatenating to the variable temp. Thus: we assume the number is 1350. First temp="", the first number is traversed 1 then add temp="One thousand", then a space and concatenate: 3- > three hundred and temp would be temp="One thousand three hundred" and so, but when the cycle is repeated, what was previously in the temp variable is deleted.