为什么我划分时会跳过数字?

Why is this skipping numbers when I divide it?

代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define BUFFER 512


void getCount(int *numCount, int *count);
int sumNumbers(int *numSum, int *sumNumOutput);

int main(void) {

  printf("Enter a number greater than 0: ");

  char string[BUFFER]; 
  int numMain = 0;
  int countMain = 0;
  int sumNumMain = 0;

  fgets(string, BUFFER, stdin); // gets user input and stores it in string

  numMain = atoi(string); // converts the string to numerical and sets sum to the value. If there is a letter in the string, it will be zero.

  int numCountMain = numMain;


int numSumNum = numMain;

  getCount(&numCountMain, &countMain); // gets how many integers there are
  sumNumbers(&numSumNum, &sumNumMain); 

  printf("Count: %d\n", countMain);
//  printf("Sum: %d\n", sumNumMain);
  return 0;
}

//shows how many integers were entered
void getCount(int *numCount, int *count){

  while(*numCount > 0){

  *numCount /= 10;
  ++*count;
}
return;
}

int sumNumbers(int *numSum, int *sumNumOutput){ // make it so that it isolates a number, then adds it to a universal sum variable
  int increment = 1;
  int count = 0;

  while(*numSum > 0){ // gets the count of the number

    while(*numSum > 0){

      *numSum /= increment;
      ++count;
      printf("numSum: %d\n",*numSum);
      increment *= 10;
    }
  }
}

假设我输入了 12345 作为数字。它可以很好地计算其中的位数,但是当它使用除法隔离各个数字时,它会跳过第三个数字。在 12345 的情况下,它将是: 12345 1234 12 0

我认为这是增量 运行 amok 的情况,但我找不到解决此问题的方法。我也知道当我解决这个问题时,它不会解决我必须隔离个人数字的问题。这就是增量的来源,我知道我必须使用模数,但如果有人能在我解决这个问题后帮助我解决这个问题,那就太好了。

此外,如果不是很明显,我假设有问题的代码是底线。

你除以 1、10、100、1000。所以你得到 12345、1234、12。

尝试

while (*numSum > 0) {
  ++count;
  printf("numSum: %d\n",*numSum);
  *numSum /= 10; 
}