C程序中的意外输出

Siv*_*eti 0 c

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

void koaneeye(){
    static int j=0;
    int n,i=0,rev=0;
    while( scanf("%d",&n) == 1)
        koaneeye();
    while(n)
    {
        i=n%10;
        rev=rev*10+i;
        n=n/10;
    }
    printf("%d\n",rev);
}

int main() {

    koaneeye();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

对于上述计划

输入:123 223 323 423 523 623

输出:325767891 326 325 324 323 322 321

为什么会有额外的号码?

She*_*tJS 5

printf语句被调用太多次了.如果您没有读取数据,则需要停止执行.因为无论如何你都在使用递归,所以你不需要循环:

if( scanf("%d",&n) != 1) return;
koaneeye();
Run Code Online (Sandbox Code Playgroud)