十进制转换2进制问题

#include<stdio.h> #include<string.h> void ten_to_two(int n,char *b) { int count = 0; char buf[128]={0}; while(1) { buf[count] = n%2; // n=n%2; n=n/2; if(n==0) break; count++; } printf("count=%d\n",count); for(int i = count;i >=0;i--) { b[i]=buf[count-i]; } } int main() { int n = 15; char buf[128]={0}; ten_to_two(n,buf); puts(buf); int i = strlen(buf); printf("i=%d\n",i); return 0; }
找个明白人 为什么我主函数里面的buf是乱码呢