C++帮我看看这个程序该怎么修改

img


char a[1000],c;
char shi[200];
int shuzi,m;
while(gets(shi))
{
int i=0,j=0;
shuzi=atoi(shi);
if(shuzi==0)
{
return 0;
}
else
{
while(shuzi!=0)
{
m=shuzi/16;
if(shuzi%16==0)
{
a[i++]='0';
}
else
{
if(shuzi%16>=10)
{
c=shuzi%16-10+'A';
a[i++]=c;
}
else
{
c=shuzi%16+'0';
a[i++]=c;
}
}
shuzi=m;

    }
}
for(j=i-1;j>=0;j--)
{
    printf("%c",a[j]);
}
printf("\n");

}

img


为什么输入1234578901234567890
会输出乱码

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

int main()
{
    char a[1000] = {0}, c;
    char* end;
    char shi[200];
    unsigned long long int shuzi, m;
    while (gets_s(shi))
    {
        int i = 0, j = 0;
        shuzi = strtoull(shi,&end,10);
        if (shuzi == 0)
        {
            return 0;
        }
        else
        {
            while (shuzi != 0)
            {
                m = shuzi / 16;
                if (shuzi % 16 == 0)
                {
                    a[i++] = '0';
                }
                else
                {
                    if (shuzi % 16 >= 10)
                    {
                        c = shuzi % 16 - 10 + 'A';
                        a[i++] = c;
                    }
                    else
                    {
                        c = shuzi % 16 + '0';
                        a[i++] = c;
                    }
                }
                shuzi = m;
            }
        }
        for (j = i - 1; j >= 0; j--)
        {
            printf("%c", a[j]);
        }
        printf("\n");
    }
    return 0;
}