Pregunta

for(int y = 0; y < 5; y++)
{   
   char cst1[2] = {info[x+2], info[x+3]};
   char cst2[2] = {info[x+5], info[x+6]};
   sales[count][atoi(&info[x]) - 1] = atoi(cst1) + atoi(cst2);
   x += 8;
}

Every time i do the following code the atoi(cst1) value is multiplied by two then added and atoi(cst2) is multiplied by 100 then added cant figure out why

¿Fue útil?

Solución

cst1 and cst2 don't appear to be NUL-terminated.

char cst1[] = {info[x+2], info[x+3], '\0'};
char cst2[] = {info[x+5], info[x+6], '\0'};
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top