找出不指定位数的正整数中的最大一位数字并求出该正整数的位数

找出不指定位数的正整数中的最大一位数字并求出该正整数的位数,这该怎么找啊

#include <stdio.h>
int main()
{
   long n;
   int t,m,max;
   m=0;max=0;
   scanf("%ld",&n);
   while(n)
  {
     t = n % 10;
     n = n / 10;
     if(t > max) max = t; //max保存各位数字的最大值.
     m++; //m用来统计该数的位数.
  }
  printf("位数:%d 最大数=%d\n",m,max); //m是该数的位数. max是各位数字中的最大值.
  return 0;
}