سؤال

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

هل كانت مفيدة؟

المحلول

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'};
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top